/* ═══════════════════════════════════════════════
   Design Tokens
   ═══════════════════════════════════════════════ */
:root {
  /* Palette — light */
  --bg:       #F0F4FF;
  --surface:  #FFFFFF;
  --raised:   #FFFFFF;
  --sunk:     #E4EAFF;
  --card:     #FFFFFF;
  --ink:      #0D1B35;
  --sub:      #3D5280;
  --muted:    #7A90B8;
  --line:     #D0DAEE;

  /* Brand */
  --blue:     #2563EB;
  --blue2:    #3B82F6;
  --blue3:    #60A5FA;
  --purple:   #7C3AED;
  --teal:     #0EA5E9;
  --on-blue:  #FFFFFF;

  /* States */
  --amber:    #D97706;
  --amber2:   #F59E0B;
  --amber-bg: rgba(217,119,6,.10);
  --ok:       #059669;
  --ok-bg:    rgba(5,150,105,.10);
  --bad:      #DC2626;
  --bad-bg:   rgba(220,38,38,.10);

  /* Gradients */
  --grad-hero: linear-gradient(135deg, #2563EB 0%, #7C3AED 100%);
  --grad-amber: linear-gradient(135deg, #D97706, #DC2626);
  --grad-ok:   linear-gradient(135deg, #059669, #0EA5E9);
  --grad-card: linear-gradient(160deg, #FFFFFF 60%, #EEF2FF 100%);

  /* Shadows */
  --sh-xs: 0 1px 2px rgba(13,27,53,.06);
  --sh-sm: 0 2px 8px rgba(13,27,53,.08), 0 1px 2px rgba(13,27,53,.04);
  --sh-md: 0 4px 20px rgba(13,27,53,.10), 0 1px 4px rgba(13,27,53,.06);
  --sh-lg: 0 8px 40px rgba(13,27,53,.14), 0 2px 8px rgba(13,27,53,.08);
  --sh-glow: 0 0 0 3px rgba(37,99,235,.25);

  /* Typography */
  --ui: "Readex Pro","Noto Kufi Arabic","Noto Sans Arabic",Tahoma,"Segoe UI",sans-serif;
  --mono: "JetBrains Mono","Fira Code",Consolas,monospace;
  --fs: 16px;

  color-scheme: light;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --MODE: dark; }
}
:root[data-theme="dark"],
:root[data-theme="dark"] *,
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:       #080F1E;
    --surface:  #0D1626;
    --raised:   #111D33;
    --sunk:     #060C18;
    --card:     #111D33;
    --ink:      #DDE8FF;
    --sub:      #7E99CC;
    --muted:    #4A6090;
    --line:     #1E2E4A;

    --blue:     #3B82F6;
    --blue2:    #60A5FA;
    --blue3:    #93C5FD;
    --purple:   #A78BFA;
    --teal:     #38BDF8;
    --on-blue:  #FFFFFF;

    --amber:    #F59E0B;
    --amber2:   #FCD34D;
    --amber-bg: rgba(245,158,11,.12);
    --ok:       #10B981;
    --ok-bg:    rgba(16,185,129,.12);
    --bad:      #F87171;
    --bad-bg:   rgba(248,113,113,.12);

    --grad-hero: linear-gradient(135deg, #1D4ED8 0%, #5B21B6 100%);
    --grad-card: linear-gradient(160deg, #111D33 60%, #0D1A30 100%);

    --sh-xs: 0 1px 3px rgba(0,0,0,.4);
    --sh-sm: 0 2px 10px rgba(0,0,0,.5);
    --sh-md: 0 4px 24px rgba(0,0,0,.55);
    --sh-lg: 0 8px 48px rgba(0,0,0,.65);
    --sh-glow: 0 0 0 3px rgba(59,130,246,.30);

    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:       #080F1E;
  --surface:  #0D1626;
  --raised:   #111D33;
  --sunk:     #060C18;
  --card:     #111D33;
  --ink:      #DDE8FF;
  --sub:      #7E99CC;
  --muted:    #4A6090;
  --line:     #1E2E4A;
  --blue:     #3B82F6;
  --blue2:    #60A5FA;
  --blue3:    #93C5FD;
  --purple:   #A78BFA;
  --teal:     #38BDF8;
  --amber:    #F59E0B;
  --amber2:   #FCD34D;
  --amber-bg: rgba(245,158,11,.12);
  --ok:       #10B981;
  --ok-bg:    rgba(16,185,129,.12);
  --bad:      #F87171;
  --bad-bg:   rgba(248,113,113,.12);
  --grad-hero: linear-gradient(135deg, #1D4ED8 0%, #5B21B6 100%);
  --grad-card: linear-gradient(160deg, #111D33 60%, #0D1A30 100%);
  --sh-xs: 0 1px 3px rgba(0,0,0,.4);
  --sh-sm: 0 2px 10px rgba(0,0,0,.5);
  --sh-md: 0 4px 24px rgba(0,0,0,.55);
  --sh-lg: 0 8px 48px rgba(0,0,0,.65);
  --sh-glow: 0 0 0 3px rgba(59,130,246,.30);
  color-scheme: dark;
}

:root[data-size="s"] { --fs: 14.5px }
:root[data-size="l"] { --fs: 18px }

/* ═══════════════════════════════════════════════
   Reset & Base
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  scroll-padding-top: env(safe-area-inset-top,0px);
  padding-top: env(safe-area-inset-top,0px);
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: var(--fs);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  transition: background .35s, color .35s;
  direction: rtl;
  padding-bottom: env(safe-area-inset-bottom,0px);
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--blue2); outline-offset: 3px; border-radius: 10px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px 80px; }

/* ═══════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px; border-radius: 14px; padding: 12px 22px; font-weight: 600;
  font-size: 1em; border: 1.5px solid transparent; min-height: 48px;
  transition: transform .12s, filter .15s, background .15s, box-shadow .15s;
  letter-spacing: .01em;
}
.btn:active:not([disabled]) { transform: scale(.97); }
.btn-primary { background: var(--blue); color: var(--on-blue); box-shadow: 0 2px 12px rgba(37,99,235,.35); }
.btn-primary:hover:not([disabled]) { filter: brightness(1.1); box-shadow: 0 4px 20px rgba(37,99,235,.5); }
.btn-ghost { background: var(--surface); border-color: var(--line); }
.btn-ghost:hover:not([disabled]) { background: var(--sunk); }
.btn-amber { background: var(--amber); color: #fff; box-shadow: 0 2px 12px rgba(217,119,6,.4); }
.btn-ok { background: var(--ok); color: #fff; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: .85em; border-radius: 10px; }
.btn-xs { min-height: 28px; padding: 3px 10px; font-size: .78em; border-radius: 8px; }
.linkbtn { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: .85em; padding: 8px; cursor: pointer; }
.iconbtn {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 13px;
  width: 44px; height: 44px; display: grid; place-items: center; transition: background .15s;
}
.iconbtn:hover { background: var(--sunk); }
.iconbtn svg { width: 20px; height: 20px; stroke: var(--ink); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.back { display: inline-flex; align-items: center; gap: 5px; color: var(--blue); font-weight: 600; padding: 6px 0; font-size: .9em; }
.back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; }

/* ═══════════════════════════════════════════════
   Utility
   ═══════════════════════════════════════════════ */
.bar { height: 8px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad-hero); border-radius: 99px; transition: width .7s cubic-bezier(.2,.8,.2,1); }
.panel { background: var(--card); border: 1.5px solid var(--line); border-radius: 22px; padding: 20px; box-shadow: var(--sh-md); margin-bottom: 14px; }
.panel h3 { margin: 0 0 12px; font-size: 1.02em; font-weight: 700; }
.hint { color: var(--muted); font-size: .85em; margin: 6px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px;
  padding: 7px 16px; font-weight: 600; font-size: .88em;
  transition: background .15s, border-color .15s, color .15s;
}
.chip[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 99px;
  padding: 3px 10px; font-size: .78em; font-weight: 700; letter-spacing: .02em;
}
.badge-blue { background: rgba(59,130,246,.15); color: var(--blue2); }
.badge-ok   { background: var(--ok-bg); color: var(--ok); }
.badge-bad  { background: var(--bad-bg); color: var(--bad); }
.badge-amber{ background: var(--amber-bg); color: var(--amber); }

/* ═══════════════════════════════════════════════
   Home — Hero
   ═══════════════════════════════════════════════ */
.hero {
  background: var(--grad-hero);
  border-radius: 26px;
  padding: 28px 24px 32px;
  margin: 16px 0 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--sh-lg);
}
.hero::before {
  content: "";
  position: absolute;
  top: -60px; left: -60px;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  pointer-events: none;
}
.hero::after {
  content: "";
  position: absolute;
  bottom: -40px; right: -20px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(255,255,255,.04);
  pointer-events: none;
}
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.hero h1 { font-size: clamp(22px,5vw,32px); font-weight: 800; color: #fff; line-height: 1.2; margin: 0; }
.hero p { color: rgba(255,255,255,.75); font-size: .88em; margin: 4px 0 0; }
.hero-settings { background: rgba(255,255,255,.15); border: 1.5px solid rgba(255,255,255,.25); border-radius: 12px; width: 42px; height: 42px; display: grid; place-items: center; flex: none; transition: background .15s; }
.hero-settings:hover { background: rgba(255,255,255,.25); }
.hero-settings svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hero-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.hero-stat { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); border-radius: 14px; padding: 12px 8px; text-align: center; backdrop-filter: blur(8px); }
.hero-stat b { display: block; font-size: 1.5em; font-weight: 800; color: #fff; line-height: 1.2; }
.hero-stat span { font-size: .75em; color: rgba(255,255,255,.7); }
.hero-bar-wrap { margin-top: 16px; }
.hero-bar-label { display: flex; justify-content: space-between; color: rgba(255,255,255,.8); font-size: .82em; margin-bottom: 6px; }
.hero-bar { height: 8px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; }
.hero-bar > i { display: block; height: 100%; background: rgba(255,255,255,.9); border-radius: 99px; transition: width .8s cubic-bezier(.2,.8,.2,1); }

/* Continue button */
.continue {
  display: flex; align-items: center; gap: 16px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 20px; padding: 18px; margin-bottom: 16px;
  text-align: right; width: 100%; cursor: pointer;
  box-shadow: var(--sh-sm); transition: border-color .15s, box-shadow .15s, transform .12s;
}
.continue:hover { border-color: var(--blue2); box-shadow: var(--sh-md); transform: translateY(-1px); }
.continue:active { transform: scale(.99); }
.continue .ic { width: 50px; height: 50px; border-radius: 15px; background: var(--grad-hero); display: grid; place-items: center; flex: none; box-shadow: 0 4px 14px rgba(37,99,235,.35); }
.continue .ic svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 2.2; }
.continue small { display: block; color: var(--muted); font-size: .8em; margin-bottom: 2px; }
.continue strong { display: block; font-weight: 700; font-size: .96em; line-height: 1.4; }

/* Calendar heatmap */
.cal-panel { background: var(--card); border: 1.5px solid var(--line); border-radius: 20px; padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--sh-xs); }
.cal-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-hd span { font-size: .82em; font-weight: 700; color: var(--sub); }
.cal-grid { display: grid; grid-template-columns: repeat(14,1fr); gap: 4px; }
.cal-day { aspect-ratio: 1; border-radius: 4px; background: var(--sunk); transition: background .2s; }
.cal-day.active { background: var(--blue2); }
.cal-day.today { box-shadow: 0 0 0 2px var(--amber); }

/* Quick actions */
.quick-actions { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.qa-btn {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 18px;
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center;
  gap: 7px; cursor: pointer; text-align: center; transition: border-color .15s, box-shadow .15s, transform .12s;
  box-shadow: var(--sh-xs);
}
.qa-btn:hover { border-color: var(--blue2); box-shadow: var(--sh-sm); transform: translateY(-2px); }
.qa-btn:active { transform: scale(.97); }
.qa-btn .qa-icon { font-size: 1.6em; line-height: 1; }
.qa-btn .qa-label { font-size: .82em; font-weight: 700; color: var(--ink); line-height: 1.3; }
.qa-btn .qa-sub { font-size: .72em; color: var(--muted); }

/* Pomodoro */
.pom-card { background: var(--card); border: 1.5px solid var(--line); border-radius: 18px; padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--sh-xs); display: flex; align-items: center; gap: 14px; }
.pom-icon { width: 44px; height: 44px; border-radius: 13px; background: var(--amber-bg); display: grid; place-items: center; flex: none; font-size: 1.4em; }
.pom-meta { flex: 1; }
.pom-lbl { font-size: .78em; color: var(--muted); font-weight: 600; }
.pom-time { font-family: var(--mono); font-size: 1.6em; font-weight: 800; color: var(--ink); line-height: 1.1; }
[data-mode="break"] .pom-time { color: var(--ok); }
[data-mode="break"] .pom-icon { background: var(--ok-bg); }
.pom-btns { display: flex; gap: 6px; }

/* Search */
.search-bar { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 11px 14px; margin-bottom: 16px; box-shadow: var(--sh-xs); transition: border-color .15s; }
.search-bar:focus-within { border-color: var(--blue2); box-shadow: var(--sh-glow); }
.search-bar svg { width: 17px; height: 17px; stroke: var(--muted); fill: none; stroke-width: 2; flex: none; }
.search-bar input { flex: 1; border: none; outline: none; background: none; font: inherit; color: var(--ink); font-size: .93em; direction: rtl; }
.search-bar input::placeholder { color: var(--muted); }

/* Lesson path */
.frame { margin-bottom: 16px; }
.unit { margin-bottom: 24px; }
.unit h2 { font-size: .85em; font-weight: 800; color: var(--muted); margin: 0 0 10px; display: flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .08em; }
.unit h2 small { font-size: .85em; font-weight: 500; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; text-transform: none; letter-spacing: 0; }
.path { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.node {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 18px; padding: 14px 16px; width: 100%; text-align: right;
  transition: border-color .18s, box-shadow .18s, transform .12s;
  box-shadow: var(--sh-xs); cursor: pointer;
}
.node:hover { border-color: var(--blue2); box-shadow: var(--sh-sm); transform: translateY(-1px); }
.node:active { transform: scale(.99); }
.node.done { border-color: rgba(5,150,105,.4); }
.node.best { border-color: var(--amber2); background: linear-gradient(var(--card), var(--card)) padding-box, var(--grad-amber) border-box; }
.node.weak { border-color: var(--bad); }
.node-badge { flex: none; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: .88em; font-weight: 800; position: relative; overflow: hidden; }
.node-badge-inner { width: 100%; height: 100%; display: grid; place-items: center; font-family: var(--mono); font-weight: 700; font-size: .9em; }
.node:not(.done):not(.best) .node-badge { background: var(--sunk); color: var(--muted); }
.node.done .node-badge { background: var(--ok-bg); color: var(--ok); }
.node.best .node-badge { background: var(--grad-amber); color: #fff; }
.node.weak .node-badge { background: var(--bad-bg); color: var(--bad); }
.node-progress { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--blue2); border-radius: 99px; }
.txt { flex: 1; min-width: 0; text-align: right; }
.txt strong { display: block; font-size: .95em; font-weight: 700; line-height: 1.35; }
.txt em { display: block; font-size: .78em; color: var(--muted); font-style: normal; margin-top: 2px; }
.chev { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2.2; flex: none; }

/* Actions section */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.ready { background: var(--ok-bg); border-radius: 16px; padding: 14px 18px; font-size: .9em; border: 1px solid rgba(5,150,105,.25); }
.ready b { display: block; margin-bottom: 4px; color: var(--ok); }

/* ═══════════════════════════════════════════════
   Lesson view
   ═══════════════════════════════════════════════ */
.lesson-hd { margin-bottom: 20px; padding-top: 16px; }
.lesson-hd h1 { font-size: clamp(20px,5vw,30px); font-weight: 800; margin: 6px 0 4px; line-height: 1.25; }
.lesson-hd .en-title { font-size: .88em; color: var(--muted); direction: ltr; text-align: start; margin: 0 0 14px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { background: var(--sunk); border: none; border-radius: 10px; padding: 8px 18px; font-size: .88em; font-weight: 600; color: var(--sub); transition: background .15s, color .15s; }
.tab.active { background: var(--blue); color: #fff; }
.tab:hover:not(.active) { background: var(--line); }

/* Read sections */
.sections section { background: var(--card); border: 1.5px solid var(--line); border-radius: 20px; padding: 20px 22px; margin-bottom: 12px; box-shadow: var(--sh-xs); }
.sections section h3 { margin: 0 0 12px; font-size: 1em; font-weight: 800; color: var(--blue2); }
.read-mark { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.read-mark span { font-size: .82em; color: var(--ok); font-weight: 600; }
.read-mark span.unread { color: var(--muted); }
.ar-txt { direction: rtl; text-align: right; line-height: 2; }
.en-txt { direction: ltr; text-align: left; font-size: .87em; color: var(--sub); margin-top: 8px; line-height: 1.7; border-top: 1px dashed var(--line); padding-top: 8px; }
body.en-only .ar-txt { display: none; }
body.en-only .en-txt { font-size: 1em; color: var(--ink); border-top: none; padding-top: 0; margin-top: 0; }
body.en-only .en-title { font-size: 1.05em; color: var(--ink); }
body.en-only .lesson-hd h1 { display: none; }
body.en-only .node .txt strong .ar-t { display: none; }
.def { background: var(--sunk); border-right: 4px solid var(--blue2); border-radius: 12px; padding: 12px 16px; margin: 10px 0; font-size: .95em; line-height: 1.8; }
.code {
  background: var(--sunk); font-family: var(--mono); font-size: .86em; border-radius: 13px;
  padding: 14px 16px; direction: ltr; text-align: left; overflow-x: auto;
  white-space: pre; line-height: 1.7; margin: 10px 0; border: 1px solid var(--line);
  position: relative;
}
/* Syntax highlighting in .code blocks */
.code .py-kw  { color: #C084FC; font-weight: 600; }
.code .py-bi  { color: #38BDF8; }
.code .py-str { color: #86EFAC; }
.code .py-num { color: #FCA5A5; }
.code .py-cmt { color: var(--muted); font-style: italic; }
.code .py-fn  { color: #FCD34D; }
.code .py-op  { color: #F97316; }

.tbl { overflow-x: auto; margin: 10px 0; }
.tbl table { width: 100%; border-collapse: collapse; font-size: .9em; }
.tbl th { background: var(--sunk); padding: 10px 14px; font-weight: 700; text-align: right; border-bottom: 2px solid var(--line); }
.tbl td { padding: 9px 14px; border-top: 1px solid var(--line); }
.tbl tr:hover td { background: var(--sunk); }
.memo {
  background: var(--amber-bg); border-radius: 12px; padding: 12px 16px;
  font-weight: 700; font-size: .9em; margin: 12px 0;
  border-right: 4px solid var(--amber); direction: rtl;
}
.memo .en-memo { font-family: var(--mono); font-size: .85em; direction: ltr; text-align: left; color: var(--sub); display: block; margin-top: 5px; }

/* ═══════════════════════════════════════════════
   Flashcards
   ═══════════════════════════════════════════════ */
.fc-scene { perspective: 1100px; margin-bottom: 18px; }
.fc {
  width: 100%; height: 280px; position: relative; cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.4,0,.2,1);
}
.fc.flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; border-radius: 22px;
  box-shadow: var(--sh-lg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 28px;
  backface-visibility: hidden; text-align: center;
  border: 1.5px solid var(--line);
}
.fc-front { background: var(--grad-card); }
.fc-back  { background: var(--grad-hero); transform: rotateY(180deg); }
.fc-back .ar-txt, .fc-back .en-txt { color: rgba(255,255,255,.95); }
.fc-back .en-txt { border-top-color: rgba(255,255,255,.25); color: rgba(255,255,255,.75); }
.fc-label { position: absolute; top: 14px; right: 18px; font-size: .7em; font-family: var(--mono); font-weight: 600; }
.fc-front .fc-label { color: var(--muted); }
.fc-back .fc-label  { color: rgba(255,255,255,.6); }
.fc-flip-hint { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: .72em; color: var(--muted); }
.fc-back .fc-flip-hint { color: rgba(255,255,255,.5); }
.fc-front .ar-txt { font-size: 1.2em; font-weight: 700; }
.fc-back .ar-txt  { font-size: 1.1em; font-weight: 700; }

.fc-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.fc-count { font-size: .88em; color: var(--muted); font-family: var(--mono); }
.fc-progress { height: 6px; background: var(--sunk); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.fc-progress > i { display: block; height: 100%; background: var(--grad-ok); border-radius: 99px; transition: width .4s; }
.fc-actions { display: flex; gap: 10px; margin-bottom: 8px; }
.fc-actions .btn { flex: 1; }
.fc-hint { text-align: center; font-size: .8em; color: var(--muted); }
.fc-sr-badge { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }

/* ═══════════════════════════════════════════════
   Quiz / Drill
   ═══════════════════════════════════════════════ */
.q-card { background: var(--card); border: 1.5px solid var(--line); border-radius: 22px; padding: 22px; margin-bottom: 16px; box-shadow: var(--sh-sm); }
.q-num { font-size: .75em; font-family: var(--mono); color: var(--muted); margin-bottom: 8px; direction: ltr; text-align: left; }
.q-text { font-size: 1em; font-weight: 600; line-height: 1.75; margin-bottom: 12px; }
.q-en { font-size: .85em; color: var(--sub); margin-bottom: 14px; direction: ltr; text-align: left; }
.options { display: flex; flex-direction: column; gap: 9px; }
.opt {
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 13px; padding: 12px 16px; text-align: right;
  transition: border-color .15s, background .15s, transform .1s;
  font-size: .94em; cursor: pointer;
}
.opt:hover:not([disabled]) { border-color: var(--blue2); background: var(--sunk); transform: translateX(-2px); }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.opt.wrong   { border-color: var(--bad); background: var(--bad-bg); }
.opt[disabled] { cursor: default; }
.explain { background: var(--amber-bg); border-radius: 12px; padding: 12px 16px; font-size: .87em; margin-top: 12px; border-right: 4px solid var(--amber); }
.tf-btns { display: flex; gap: 12px; }
.tf-btns .btn { flex: 1; font-size: 1em; }
.match-col { display: flex; flex-direction: column; gap: 9px; }
.match-item { background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 16px; font-size: .9em; cursor: pointer; transition: border-color .15s, background .15s; }
.match-item.sel { border-color: var(--blue2); background: var(--sunk); }
.match-item.matched { border-color: var(--ok); background: var(--ok-bg); }
.match-item.wrong-match { border-color: var(--bad); background: var(--bad-bg); }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.drill-bar { margin-bottom: 14px; }
.drill-bar-meta { display: flex; justify-content: space-between; font-size: .78em; color: var(--muted); margin-bottom: 5px; }

/* Score */
.score-wrap { text-align: center; padding: 24px 0 16px; }
.score-ring { width: 130px; height: 130px; margin: 0 auto 18px; }
.score-ring svg { width: 100%; height: 100%; }
.score-ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.score-ring .bg { stroke: var(--sunk); }
.score-ring .fg { transition: stroke-dashoffset .9s ease; }
.score-num { text-anchor: middle; dominant-baseline: middle; font-size: 26px; font-weight: 800; fill: var(--ink); }
.score-grade { font-size: 1.3em; font-weight: 800; margin: 0 0 6px; }
.score-sub { color: var(--muted); font-size: .9em; margin-bottom: 20px; }
.res-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.res-item { display: flex; align-items: flex-start; gap: 10px; font-size: .88em; padding: 10px 14px; border-radius: 12px; background: var(--surface); }
.res-item.c { background: var(--ok-bg); }
.res-item.w { background: var(--bad-bg); }
.res-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 6px; }
.c .res-dot { background: var(--ok); }
.w .res-dot { background: var(--bad); }

/* ═══════════════════════════════════════════════
   Setup Quiz
   ═══════════════════════════════════════════════ */
.setup-lesson { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.setup-lesson input { width: 18px; height: 18px; accent-color: var(--blue); flex: none; }

/* ═══════════════════════════════════════════════
   Settings sheet
   ═══════════════════════════════════════════════ */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 200; padding: 0 8px; backdrop-filter: blur(4px); }
.sheet { background: var(--card); border-radius: 26px 26px 0 0; width: 100%; max-width: 520px; padding: 24px 24px 28px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--sh-lg); }
.sheet-handle { width: 48px; height: 5px; border-radius: 99px; background: var(--line); margin: -8px auto 4px; }
.sheet h3 { margin: 0; font-size: 1.1em; font-weight: 800; }
.grp { display: flex; flex-direction: column; gap: 8px; font-size: .9em; font-weight: 600; }
.preview { background: var(--sunk); border-radius: 12px; padding: 12px 14px; font-size: .9em; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; bottom: calc(env(safe-area-inset-bottom,0px) + 28px);
  left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 22px;
  border-radius: 99px; font-size: .88em; z-index: 400; white-space: nowrap;
  box-shadow: var(--sh-lg); animation: fadeup .25s ease;
  display: flex; align-items: center; gap: 8px; font-weight: 600;
}
@keyframes fadeup { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* Achievement popup */
.achievement-popup {
  position: fixed; top: 20px; right: 16px; left: 16px; max-width: 360px;
  margin: 0 auto; z-index: 500;
  background: linear-gradient(135deg, #D97706, #F59E0B);
  color: #fff; border-radius: 18px; padding: 16px 18px;
  box-shadow: 0 8px 32px rgba(217,119,6,.5);
  animation: slide-in .35s cubic-bezier(.34,1.56,.64,1);
  display: flex; align-items: center; gap: 14px;
}
.achievement-popup .ach-icon { font-size: 2em; flex: none; }
.achievement-popup .ach-text { }
.achievement-popup .ach-title { font-size: .75em; opacity: .8; font-weight: 600; }
.achievement-popup .ach-name { font-size: 1.02em; font-weight: 800; }
@keyframes slide-in { from { opacity:0; transform:translateY(-20px) scale(.9); } to { opacity:1; transform:translateY(0) scale(1); } }

/* Confetti canvas */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 450; }

/* ═══════════════════════════════════════════════
   Python Lab
   ═══════════════════════════════════════════════ */
.lab-header { display: flex; align-items: center; gap: 16px; padding: 20px 0 16px; border-bottom: 1.5px solid var(--line); margin-bottom: 16px; }
.lab-header-title { font-size: 1.4em; font-weight: 800; background: var(--grad-hero); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.lab-header-sub { font-size: .8em; color: var(--muted); margin-top: 1px; }
.lab-layout { display: flex; gap: 14px; align-items: flex-start; }
.lab-sidebar {
  width: 210px; flex: none; display: flex; flex-direction: column; gap: 2px;
  max-height: calc(100vh - 100px); overflow-y: auto; position: sticky; top: 12px;
  scrollbar-width: thin;
}
.lab-group { margin-bottom: 4px; }
.lab-group-hd { font-size: .68em; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 8px 10px 3px; direction: ltr; text-align: left; }
.lab-ex-btn {
  width: 100%; text-align: left; direction: ltr; background: none; border: none;
  padding: 7px 10px; border-radius: 9px; font-size: .82em; color: var(--sub);
  cursor: pointer; transition: background .12s, color .12s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lab-ex-btn:hover { background: var(--sunk); color: var(--ink); }
.lab-ex-btn.active { background: var(--blue); color: #fff; font-weight: 700; }

.lab-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.lab-ex-info { background: var(--amber-bg); border: 1px solid rgba(217,119,6,.3); border-radius: 14px; padding: 14px 16px; border-right: 4px solid var(--amber); }
.lab-ex-title { font-weight: 800; font-size: 1em; margin-bottom: 4px; }
.lab-ex-desc { font-size: .85em; color: var(--sub); line-height: 1.65; }

.lab-block { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--sh-xs); }
.lab-block-hd { display: flex; align-items: center; justify-content: space-between; padding: 9px 14px; background: var(--sunk); font-size: .8em; font-weight: 700; gap: 8px; color: var(--sub); }
.lab-block-hd .hd-left { display: flex; align-items: center; gap: 7px; }

/* Syntax-highlighted editor */
.lab-editor-outer { position: relative; background: var(--raised); min-height: 200px; }
.lab-highlight {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  font-family: var(--mono); font-size: .87em; line-height: 1.7;
  padding: 12px 14px 12px 48px; white-space: pre-wrap; word-break: break-all;
  overflow: hidden; color: transparent; /* just for layout — colored spans show */
}
.lab-code {
  position: relative; z-index: 2;
  width: 100%; min-height: 200px; max-height: 440px; resize: vertical;
  border: none; outline: none; background: transparent;
  font-family: var(--mono); font-size: .87em; line-height: 1.7;
  padding: 12px 14px 12px 48px; color: var(--ink); caret-color: var(--blue2);
  direction: ltr; text-align: left; tab-size: 4; white-space: pre;
  overflow: auto; display: block;
}
.lab-lines-abs {
  position: absolute; top: 0; left: 0; width: 40px; z-index: 3;
  padding: 12px 6px 12px 0; font-family: var(--mono); font-size: .87em;
  line-height: 1.7; color: var(--muted); text-align: right;
  pointer-events: none; overflow: hidden;
  border-right: 1px solid var(--line); background: var(--sunk);
  user-select: none;
}
.lab-lines-abs span { display: block; }

/* Syntax colors (lab) */
.py-kw  { color: #C084FC; }
.py-bi  { color: #38BDF8; }
.py-str { color: #86EFAC; }
.py-num { color: #FCA5A5; }
.py-cmt { color: var(--muted); font-style: italic; }
.py-fn  { color: #FCD34D; }
.py-op  { color: #F97316; }
.py-punc{ color: var(--sub); }

.lab-inputs {
  width: 100%; min-height: 68px; max-height: 120px; resize: vertical;
  border: none; outline: none; padding: 10px 14px; font-family: var(--mono);
  font-size: .85em; line-height: 1.65; background: transparent; color: var(--ink);
  direction: ltr; text-align: left; display: block; box-sizing: border-box;
}
.lab-output {
  margin: 0; padding: 12px 14px; font-family: var(--mono); font-size: .85em;
  line-height: 1.7; direction: ltr; text-align: left; white-space: pre-wrap;
  word-break: break-all; min-height: 60px; max-height: 300px; overflow-y: auto;
  color: var(--ink);
}
.lab-output.has-error { color: var(--bad); }
.lab-expected { background: var(--ok-bg); border-top: 1px solid var(--line); color: var(--ok); }
.lab-status { font-size: .76em; font-family: var(--mono); padding: 3px 9px; border-radius: 7px; background: var(--sunk); border: 1px solid var(--line); font-weight: 600; }
.lab-status.running { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.lab-status.ok  { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.lab-status.err { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
kbd { display: inline-block; font-family: var(--mono); font-size: .74em; padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--sunk); color: var(--muted); }

/* ═══════════════════════════════════════════════
   Quick Reference
   ═══════════════════════════════════════════════ */
.qref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.qref-card { background: var(--card); border: 1.5px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--sh-xs); }
.qref-card h4 { font-size: .82em; font-weight: 800; color: var(--blue2); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 7px; }
.qref-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; font-size: .82em; }
.qref-code { font-family: var(--mono); color: var(--blue3); flex: none; }
.qref-desc { color: var(--sub); }

/* ═══════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════ */
@media(max-width:700px) {
  .lab-layout { flex-direction: column; }
  .lab-sidebar { width: 100%; max-height: none; position: static; flex-direction: row; flex-wrap: wrap; overflow-x: auto; gap: 4px; }
  .lab-group { margin-bottom: 0; }
  .lab-group-hd { display: none; }
  .lab-ex-btn { white-space: nowrap; padding: 5px 10px; }
  .qref-grid { grid-template-columns: 1fr; }
}
@media(max-width:480px) {
  .match-grid { grid-template-columns: 1fr; }
  .hero-stats { gap: 7px; }
  .hero-stat b { font-size: 1.3em; }
  .quick-actions { grid-template-columns: repeat(3,1fr); gap: 8px; }
  .qa-btn { padding: 12px 6px; }
  .qa-btn .qa-label { font-size: .74em; }
}
@media(prefers-reduced-motion:reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
