/* رياضياتي — Layout: one centered phone column on squared copybook paper (light) / blackboard (dark);
   sticky top bar, fixed bottom tab bar. Red pen marks mistakes, green ticks mark right answers. */
:root {
  --paper: #F6F8FC;
  --grid: rgba(35, 70, 200, 0.075);
  --surface: #FFFFFF;
  --ink: #13233F;
  --muted: #5B6A84;
  --line: #DAE1EE;
  --accent: #2346C8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7ECFB;
  --red: #CF3427;
  --red-soft: #FCEAE7;
  --green: #137A3B;
  --green-soft: #E2F3E7;
  --hl: #FFD43B;
  --hl-ink: #3F3000;
  --shadow: 0 1px 0 rgba(19, 35, 63, 0.06), 0 6px 18px -10px rgba(19, 35, 63, 0.25);

  --f-display: "Reem Kufi", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --f-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --f-math: "STIX Two Text", "Cambria Math", "Times New Roman", serif;

  --r: 14px;
  --col: 560px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15221D; --grid: rgba(225, 240, 230, 0.045); --surface: #1D2D27; --ink: #EDF3EE; --muted: #9FB3A8;
    --line: #2D4038; --accent: #92B4FF; --accent-ink: #0E1A33; --accent-soft: #233A47; --red: #FF8B7B; --red-soft: #3A2622;
    --green: #7BD99A; --green-soft: #1E3A2A; --hl: #F3D35B; --hl-ink: #2A2200; --shadow: 0 1px 0 rgba(0,0,0,.25), 0 8px 20px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #15221D; --grid: rgba(225, 240, 230, 0.045); --surface: #1D2D27; --ink: #EDF3EE; --muted: #9FB3A8;
  --line: #2D4038; --accent: #92B4FF; --accent-ink: #0E1A33; --accent-soft: #233A47; --red: #FF8B7B; --red-soft: #3A2622;
  --green: #7BD99A; --green-soft: #1E3A2A; --hl: #F3D35B; --hl-ink: #2A2200; --shadow: 0 1px 0 rgba(0,0,0,.25), 0 8px 20px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 16px/1.7 var(--f-body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100%;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; line-height: 1.35; margin: 0; text-wrap: balance; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in, .view, .tabbar-in { max-width: var(--col); margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: 600 1.25rem/1 var(--f-math); }
.brand-name { font: 700 1.2rem/1 var(--f-display); }
.chips { display: flex; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); font-weight: 600; font-size: .9rem; font-variant-numeric: tabular-nums; }
.chip svg { width: 16px; height: 16px; }
.chip.flame { background: var(--red-soft); color: var(--red); }
.chip.xp { background: var(--hl); color: var(--hl-ink); }

.view { padding-block: 18px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom, 0px)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; outline: none; }
.view > *, .stats > *, .badges > *, .gen-grid > * { min-width: 0; }
.ltr { direction: ltr; unicode-bidi: isolate; }

.tabbar { position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabbar-in { display: grid; grid-template-columns: repeat(4, 1fr); height: var(--nav-h); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .78rem; font-weight: 500; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on svg { stroke-width: 2.3; }

/* ---------- generic ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.eyebrow { font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--accent); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; cursor: pointer; transition: transform .08s ease; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .92rem; }

.bar { height: 10px; border-radius: 99px; background: var(--accent-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.bar.hl > i { background: var(--hl); }

/* math */
.m { font-family: var(--f-math); font-size: 1.08em; unicode-bidi: isolate; white-space: nowrap; direction: ltr; }
.m sup, .m sub { font-size: .68em; line-height: 0; }
.fr { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .82em; line-height: 1.1; margin-inline: 2px; }
.fr > span:first-child { border-bottom: 1.2px solid currentColor; padding-inline: 2px; }

/* ---------- home ---------- */
.hello { display: grid; gap: 14px; }
.hello h1 { font-size: 1.5rem; }
.rank-row { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.goal { display: flex; align-items: center; gap: 14px; }
.ring { width: 64px; height: 64px; flex: none; }
.ring circle { fill: none; stroke-width: 7; }
.ring .t { stroke: var(--accent-soft); }
.ring .v { stroke: var(--hl); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .5s ease; }
.ring text { font: 700 15px var(--f-body); fill: var(--ink); }

.levels { display: grid; gap: 10px; }
.level { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; text-decoration: none; }
.lv-badge { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font: 600 1.35rem/1 var(--f-math); background: var(--accent-soft); color: var(--accent); }
.level .bar { margin-top: 6px; height: 6px; }
.chev { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; }

.continue { display: grid; gap: 10px; border-color: var(--accent); }

/* ---------- lessons ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--accent-soft); }
.seg button { border: 0; background: transparent; min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.lesson-item { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; text-decoration: none; }
.num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 600 1rem var(--f-math); border: 1.5px solid var(--line); }
.num.done { background: var(--green); border-color: var(--green); color: var(--surface); }
.num.done svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 3; }
.grade { font: 700 .95rem var(--f-math); color: var(--red); font-variant-numeric: tabular-nums; white-space: nowrap; }

.lesson-head { display: grid; gap: 6px; }
.points { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.points li { position: relative; padding-inline-start: 22px; }
.points li::before { content: ""; position: absolute; inset-inline-start: 4px; top: .7em; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); transform: rotate(45deg); }
.example { border-style: dashed; border-color: var(--accent); background: var(--surface); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; animation: rise .3s ease both; }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font: 600 .9rem var(--f-math); }
.result { padding: 10px 14px; border-radius: 10px; background: var(--green-soft); color: var(--ink); font-weight: 600; animation: rise .3s ease both; }

/* ---------- quiz ---------- */
.quiz-top { display: grid; gap: 8px; }
.qcount { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.question { font-size: 1.3rem; font-weight: 600; line-height: 1.8; padding-block: 8px; }
.options { display: grid; gap: 10px; }
.opt { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); text-align: start; font-size: 1.08rem; cursor: pointer; }
.opt .key { width: 28px; height: 28px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .85rem; }
.opt:hover:not([disabled]) { border-color: var(--accent); }
.opt[disabled] { cursor: default; }
.opt.right { border-color: var(--green); background: var(--green-soft); }
.opt.right .key { background: var(--green); color: var(--surface); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt.wrong .key { background: var(--red); color: var(--surface); }
.opt.wrong .txt { text-decoration: line-through; text-decoration-color: var(--red); text-decoration-thickness: 2px; }
.opt.dim { opacity: .55; }
.feedback { display: grid; gap: 6px; padding: 14px; border-radius: 12px; border: 1.5px solid; animation: rise .25s ease both; }
.feedback.ok { border-color: var(--green); background: var(--green-soft); }
.feedback.ko { border-color: var(--red); background: var(--red-soft); }
.feedback b { font-family: var(--f-display); font-size: 1.05rem; }
.feedback.ok b { color: var(--green); }
.feedback.ko b { color: var(--red); }

.score { display: grid; justify-items: center; gap: 14px; text-align: center; padding-block: 22px; }
.stamp { width: 128px; height: 128px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 3px solid var(--red); color: var(--red); transform: rotate(-8deg); font-family: var(--f-math); font-variant-numeric: tabular-nums; }
.stamp b { font-size: 2.5rem; line-height: 1.05; font-weight: 600; }
.stamp span { font-size: 1.15rem; line-height: 1.3; border-top: 2px solid var(--red); padding-inline: 12px; margin-top: 2px; }
.xp-gain { display: inline-flex; padding: 4px 12px; border-radius: 99px; background: var(--hl); color: var(--hl-ink); font-weight: 700; }

/* ---------- practice ---------- */
.gen-group { display: grid; gap: 10px; }
.gen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gen { display: grid; gap: 4px; text-align: start; cursor: pointer; min-height: 92px; align-content: start; }
.gen:hover { border-color: var(--accent); }
.gen h3 { font-size: 1rem; }
.gen .best { font-size: .8rem; color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { display: grid; gap: 2px; }
.stat b { font: 700 1.6rem/1.2 var(--f-math); font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge { display: grid; gap: 4px; justify-items: center; text-align: center; padding: 14px 10px; }
.medal { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--hl); color: var(--hl-ink); }
.medal svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.badge.locked { opacity: .5; }
.badge.locked .medal { background: var(--accent-soft); color: var(--muted); }
.badge b { font-size: .92rem; }
.badge span { font-size: .78rem; color: var(--muted); line-height: 1.5; }
.field { display: grid; gap: 6px; }
.field input { font: inherit; min-height: 48px; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.danger { color: var(--red); border-color: var(--red); }

.toast { position: fixed; z-index: 40; inset-inline: 16px; bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom, 0px)); max-width: 420px; margin-inline: auto; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); font-weight: 600; text-align: center; box-shadow: var(--shadow); animation: rise .25s ease both; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
