:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #17201c;
  --muted: #5d6a63;
  --line: #dde3dc;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 6px 20px rgba(20, 30, 25, .06);
  --primary: #e0782b;
  --intermediate: #2f6fd0;
  --preparatory: #7b4bc4;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e8eee9; --muted: #9aa8a0;
    --line: #2a3530; --accent: #2bb3a4; --accent-ink: #06201d; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    --primary: #f0924f; --intermediate: #5f95ea; --preparatory: #a27ce0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e8eee9; --muted: #9aa8a0;
  --line: #2a3530; --accent: #2bb3a4; --accent-ink: #06201d; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --primary: #f0924f; --intermediate: #5f95ea; --preparatory: #a27ce0; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 16px/1.6 "Tajawal", "Segoe UI", Tahoma, system-ui, sans-serif;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* شريط علوي */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px max(16px, calc((100% - 1160px) / 2)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { display: block; font-size: 17px; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo {
  flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 20px;
}
.top-actions { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: flex-end; min-width: 0; }
.search {
  display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 12px; height: 40px; width: min(320px, 100%); min-width: 0;
}
.search svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex: none; color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; width: 100%; min-width: 0; }
.icon-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}

.crumbs { padding: 14px max(16px, calc((100% - 1160px) / 2)) 0; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs a { color: var(--accent); font-weight: 500; }
.crumbs span[aria-hidden] { opacity: .5; padding: 0 2px; }

main { flex: 1; width: 100%; max-width: 1192px; margin: 0 auto; padding: 8px 16px 40px; outline: 0; }
.loading { color: var(--muted); text-align: center; padding: 60px 0; }

h1 { font-size: clamp(24px, 4.5vw, 34px); line-height: 1.25; margin: 14px 0 4px; font-weight: 800; }
.lead { color: var(--muted); margin: 0 0 22px; }
h2 { font-size: 19px; margin: 26px 0 12px; font-weight: 700; }

/* بطاقات المراحل */
.stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.stage {
  --c: var(--accent); position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 8px;
  padding: 22px; min-height: 190px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.stage::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--c); }
.stage:hover { transform: translateY(-2px); border-color: var(--c); }
.stage .num { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 26px; font-weight: 800;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.stage h3 { margin: 6px 0 0; font-size: 22px; }
.stage p { margin: 0; color: var(--muted); font-size: 14px; }
.stage .go { margin-top: auto; color: var(--c); font-weight: 700; font-size: 14px; }
.c-primary { --c: var(--primary); } .c-intermediate { --c: var(--intermediate); } .c-preparatory { --c: var(--preparatory); }

/* الصفوف */
.grades { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.grade {
  --c: var(--accent); display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.grade:hover { transform: translateY(-2px); border-color: var(--c); }
.grade .lvl { font-size: 34px; font-weight: 800; color: var(--c); line-height: 1; }
.grade b { font-size: 17px; }
.grade small { color: var(--muted); font-size: 13px; }
.grade.sci .tag, .grade.lit .tag { align-self: flex-start; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.level-group { margin-bottom: 8px; }
.level-group .grades { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* المواد */
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.subject {
  --h: 170; display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.subject:hover { transform: translateY(-2px); border-color: hsl(var(--h) 55% 45%); }
.subject .ic {
  flex: none; width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; font-size: 22px;
  background: hsl(var(--h) 60% 45% / .14); color: hsl(var(--h) 55% 38%);
}
:root[data-theme="dark"] .subject .ic { color: hsl(var(--h) 60% 70%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .subject .ic { color: hsl(var(--h) 60% 70%); } }
.subject .meta { min-width: 0; flex: 1; }
.subject b { display: block; font-size: 16px; }
.subject small { color: var(--muted); font-size: 13px; }
.bar { height: 5px; border-radius: 99px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* الفصول */
.subject-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 14px 0 18px; }
.subject-head .ic { width: 60px; height: 60px; font-size: 28px; border-radius: 16px; }
.subject-head h1 { margin: 0; }
.subject-head .lead { margin: 0; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 12px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); border: 0; cursor: pointer;
}
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.chapters { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.chapters a {
  display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); transition: border-color .15s, background .15s;
}
.chapters a:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.chapters .n { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700;
  background: var(--surface-2); color: var(--muted); font-size: 14px; }
.chapters .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.chapters .where { display: block; color: var(--muted); font-size: 12.5px; }
.chapters .p { flex: none; font-size: 12px; font-weight: 700; color: var(--accent); }

.empty { color: var(--muted); padding: 30px 0; text-align: center; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 18px 16px 26px; border-top: 1px solid var(--line); }

@media (max-width: 560px) {
  .brand small { display: none; }
  .brand b { font-size: 15px; }
  .top { gap: 8px; }
  .search { width: 100%; }
  .grades { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .level-group .grades { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .subjects { grid-template-columns: 1fr; }
  .stage { min-height: 0; }
}
@media (max-width: 380px) { .brand > span:last-child { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* الحساب */
.acct-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 999px;
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; white-space: nowrap;
}
.acct-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.acct-btn.in { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.sheet {
  width: min(420px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px 22px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(10, 15, 13, .55); backdrop-filter: blur(2px); }
.sheet-close { position: absolute; inset-inline-end: 10px; top: 8px; margin: 0; }
.sheet-close button { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.sheet h2 { margin: 0 0 6px; font-size: 21px; }
.sheet p { margin: 0 0 14px; color: var(--muted); font-size: 14.5px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field input {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: 18px; padding: 0 14px; direction: ltr; text-align: left; letter-spacing: .5px;
}
.field input.code { text-align: center; letter-spacing: 10px; font-size: 24px; font-weight: 700; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sheet .btn { width: 100%; justify-content: center; height: 48px; }
.sheet .btn[disabled] { opacity: .6; cursor: wait; }
.msg { min-height: 20px; font-size: 14px; margin: 8px 0 0; }
.msg.err { color: #c2410c; }
.dev-hint { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); border-radius: 10px; padding: 8px 12px; font-size: 13.5px; margin-bottom: 12px; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 6px 0; }
.kv { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.kv li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14.5px; }
.kv li span:last-child { color: var(--muted); }
#ts { margin-bottom: 12px; min-height: 0; }

/* حالة الفصول */
.badge { flex: none; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.free { background: color-mix(in srgb, #16a34a 15%, transparent); color: #15803d; }
:root[data-theme="dark"] .badge.free { color: #4ade80; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.free { color: #4ade80; } }
.lock { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.chapters a.locked .t { color: var(--muted); }
.notice {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; margin: 0 0 18px;
  background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
}
.notice b { display: block; }
.notice p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.notice .btn { flex: none; margin-inline-start: auto; }
@media (max-width: 560px) {
  .acct-btn { padding: 0 11px; }
  .acct-btn span { display: none; }
  .notice { flex-wrap: wrap; }
  .notice .btn { width: 100%; justify-content: center; }
}

/* الباقات وكروت التفعيل */
.card-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 22px; box-shadow: var(--shadow); }
.card-box h2 { margin: 0 0 4px; font-size: 18px; }
.card-box p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.redeem { display: flex; gap: 8px; flex-wrap: wrap; }
.code-in {
  flex: 1; min-width: 0; width: 100%; max-width: 360px; height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 700 19px/1 ui-monospace, Consolas, monospace; letter-spacing: 1.5px; padding: 0 12px; text-align: center;
}
.code-in:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.redeem .btn { height: 48px; }
.msg.ok { color: #15803d; font-weight: 700; }
:root[data-theme="dark"] .msg.ok { color: #4ade80; }
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.plan { display: flex; flex-direction: column; gap: 8px; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.plan > b { font-size: 18px; }
.plan > p { margin: 0; color: var(--muted); font-size: 14px; }
.plan .scopes { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.plan .scopes li::before { content: "✓ "; color: var(--accent); font-weight: 800; }
.plan .price { font-size: 26px; font-weight: 800; margin-top: auto; padding-top: 6px; }
.plan .price small { font-size: 14px; color: var(--muted); font-weight: 500; }
.plan .btn { justify-content: center; }
.muted-s { color: var(--muted); font-size: 13px; margin: 0; }
.notice.ok { background: color-mix(in srgb, #16a34a 10%, var(--surface)); border-color: color-mix(in srgb, #16a34a 35%, var(--line)); }
.notice.err { background: color-mix(in srgb, #dc2626 8%, var(--surface)); border-color: color-mix(in srgb, #dc2626 35%, var(--line)); }
@media (max-width: 560px) { .redeem .btn { width: 100%; justify-content: center; } .code-in { max-width: none; } }
