/* ============ ألوان عالية التباين ============ */
:root {
  --bg: #ffffff; --surface: #f1f3f7; --surface2: #e4e8ef;
  --text: #0a0c10; --muted: #353c48; --border: #8b95a5;
  --primary: #1747c9; --primary-text: #ffffff;
  --ok: #046c4e; --ok-bg: #d8f5e8; --bad: #b3131b; --bad-bg: #fde2e2;
  --gold: #8a4b00; --gold-bg: #fff0c2;
  --code-bg: #f7f8fa; --code-text: #0a0c10;
  --tag: #9b1c7a; --shadow: 0 2px 10px rgba(0,0,0,.08);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0b0f17; --surface: #151c28; --surface2: #1f2836;
  --text: #f7f9fc; --muted: #c9d1dd; --border: #4a5568;
  --primary: #7db4ff; --primary-text: #061226;
  --ok: #5ee6a8; --ok-bg: #0f3326; --bad: #ff8d8d; --bad-bg: #3a1416;
  --gold: #ffd166; --gold-bg: #3a2c06;
  --code-bg: #0f141d; --code-text: #f1f5f9;
  --tag: #ff9de2; --shadow: 0 2px 10px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  font-size: 18px; line-height: 1.75;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 760px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 16px 24px; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 10px; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 10px; }
a { color: var(--primary); }
code, pre, textarea.code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
:not(pre) > code {
  direction: ltr; unicode-bidi: isolate; display: inline-block;
  background: var(--surface2); color: var(--tag);
  padding: 0 6px; border-radius: 6px; font-size: .86em; line-height: 1.6;
}
pre.snip {
  direction: ltr; text-align: left; background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  font-size: 15px; line-height: 1.6; overflow-x: auto; margin: 10px 0 0; white-space: pre;
}
small, .muted { color: var(--muted); }

/* ============ عناصر عامة ============ */
.card {
  background: var(--surface); border: 1px solid var(--surface2); border-radius: 18px;
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 1.05rem;
  min-height: 52px; padding: 10px 22px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--primary); background: var(--primary); color: var(--primary-text);
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.btn.full { width: 100%; }
.btn:disabled { cursor: not-allowed; background: var(--surface2); border-color: var(--surface2); color: var(--muted); }
.btn.sm { min-height: 42px; padding: 6px 14px; font-size: .95rem; border-radius: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
input.field {
  width: 100%; font: inherit; font-size: 1.2rem; padding: 14px 16px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--bg); color: var(--text);
}
input.field:focus { outline: 3px solid var(--primary); border-color: var(--primary); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--surface2); font-weight: 700; font-size: .95rem; }
.pill.gold { background: var(--gold-bg); color: var(--gold); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }

/* ============ الرئيسية ============ */
.hello { font-size: 1.5rem; font-weight: 700; margin-bottom: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px 8px; text-align: center; border: 1px solid var(--surface2); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; }
.stat span { font-size: .85rem; color: var(--muted); font-weight: 600; }
.bar { height: 12px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .5s; }
.today { border: 2px solid var(--primary); }
.today .tag { color: var(--primary); font-weight: 700; font-size: .9rem; }
.goal { display: flex; gap: 10px; }
.goal div { flex: 1; padding: 10px; border-radius: 12px; background: var(--bg); border: 2px solid var(--surface2); text-align: center; font-weight: 600; font-size: .95rem; }
.goal div.done { border-color: var(--ok); color: var(--ok); }

/* ============ المنهج ============ */
.phase { border-radius: 18px; padding: 16px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--surface2); }
.phase.locked { opacity: .6; }
.phase h3 { margin: 0; }
.items { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--bg); border: 2px solid var(--surface2); font: inherit; color: var(--text);
  text-align: right; width: 100%; cursor: pointer;
}
.item .ic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface2); font-weight: 700; flex: none; }
.item.done .ic { background: var(--ok); color: var(--bg); }
.item.next { border-color: var(--primary); }
.item.next .ic { background: var(--primary); color: var(--primary-text); }
.item.lock { cursor: default; color: var(--muted); }
.item .meta { font-size: .85rem; color: var(--muted); }
.week-h { font-weight: 700; color: var(--muted); font-size: .9rem; margin-top: 6px; }

/* ============ الدرس ============ */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar .x { font-size: 1.4rem; background: none; border: 0; color: var(--text); width: 44px; height: 44px; cursor: pointer; flex: none; }
.topbar .bar { flex: 1; }
.steps-label { font-size: .9rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.ai-tip { border-inline-start: 5px solid var(--gold); background: var(--gold-bg); color: var(--text); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.ai-tip b.t { color: var(--gold); display: block; margin-bottom: 2px; }
.task { background: var(--surface); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px; border: 2px solid var(--surface2); }
.task.bug { border-color: var(--bad); }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; padding: 18px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg) 35%); }
.actions { padding-top: 14px; }
body.in-lesson { padding-bottom: 20px; }

/* ============ المحرر ============ */
.ed-tabs { display: none; gap: 6px; margin-bottom: 8px; }
.ed-tabs button { flex: 1; font: inherit; font-weight: 700; padding: 10px; border-radius: 12px; border: 2px solid var(--surface2); background: var(--surface); color: var(--text); cursor: pointer; }
.ed-tabs button.on { border-color: var(--primary); background: var(--primary); color: var(--primary-text); }
.ed-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-pane { display: flex; flex-direction: column; min-width: 0; }
textarea.code {
  width: 100%; min-height: 320px; resize: vertical; direction: ltr; text-align: left;
  background: var(--code-bg); color: var(--code-text); border: 2px solid var(--border);
  border-radius: 14px; padding: 12px; font-size: 15px; line-height: 1.65; tab-size: 2;
  white-space: pre; overflow: auto; outline: none;
}
textarea.code:focus { border-color: var(--primary); }
.symbols { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; direction: ltr; scrollbar-width: none; }
.symbols::-webkit-scrollbar { display: none; }
.symbols button {
  flex: none; min-width: 44px; height: 44px; font-family: 'JetBrains Mono', monospace; font-size: 18px; font-weight: 700;
  border-radius: 10px; border: 2px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.symbols button:active { background: var(--primary); color: var(--primary-text); }
iframe.preview { width: 100%; min-height: 320px; flex: 1; border: 2px solid var(--border); border-radius: 14px; background: #fff; }
.ed-tools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ed-tools .btn { flex: 1; min-width: 120px; }
@media (max-width: 720px) {
  .ed-tabs { display: flex; }
  .ed-wrap { grid-template-columns: 1fr; }
  .ed-wrap[data-view="code"] .pv { display: none; }
  .ed-wrap[data-view="preview"] .cd { display: none; }
}

.checks { list-style: none; padding: 0; margin: 12px 0 0; }
.checks li { padding: 8px 12px; border-radius: 10px; margin-bottom: 6px; font-weight: 600; display: flex; gap: 8px; }
.checks li.pass { background: var(--ok-bg); color: var(--ok); }
.checks li.fail { background: var(--bad-bg); color: var(--bad); }
.hint { background: var(--gold-bg); border-radius: 12px; padding: 10px 14px; margin-top: 8px; }
.hint b { color: var(--gold); }

/* ============ الأسئلة ============ */
.q { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  font: inherit; text-align: right; padding: 14px 16px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--border); background: var(--bg); color: var(--text); font-weight: 600;
}
.opt.right { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.opt:disabled { cursor: default; }
.why { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface2); }

/* ============ النتيجة ============ */
.celebrate { text-align: center; padding: 26px 10px; }
.celebrate .big { font-size: 4rem; line-height: 1; margin-bottom: 10px; animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.xp-gain { font-size: 2rem; font-weight: 700; color: var(--ok); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 14px; background: var(--bg); border: 2px solid var(--surface2); font-size: .85rem; font-weight: 600; }
.badge i { display: block; font-style: normal; font-size: 2rem; }
.badge.off { opacity: .35; filter: grayscale(1); }

/* ============ الشريط السفلي ============ */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
#tabbar[hidden] { display: none; }
#tabbar button {
  flex: 1; background: none; border: 0; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; cursor: pointer; position: relative; border-radius: 12px;
}
#tabbar button span { font-size: 1.35rem; line-height: 1; }
#tabbar button.on { color: var(--primary); background: var(--surface2); }
#revBadge { position: absolute; top: 2px; left: 50%; margin-left: 8px; background: var(--bad); color: #fff; font-size: .7rem; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px; }
#revBadge[hidden] { display: none; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 14px; font-weight: 700; z-index: 50;
  transition: .25s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.seg { display: flex; gap: 6px; }
.seg button { flex: 1; font: inherit; font-weight: 700; padding: 10px; border-radius: 12px; border: 2px solid var(--surface2); background: var(--bg); color: var(--text); cursor: pointer; }
.seg button.on { border-color: var(--primary); color: var(--primary); }
textarea.backup { width: 100%; min-height: 90px; font-family: 'JetBrains Mono', monospace; font-size: 12px; direction: ltr; border-radius: 12px; border: 2px solid var(--border); background: var(--bg); color: var(--text); padding: 10px; }
.center { text-align: center; }
.logo-big { font-family: 'JetBrains Mono', monospace; font-size: 3.4rem; font-weight: 700; color: var(--primary); direction: ltr; }
