/* ---------- الألوان: أساس محايد + لون واحد مميّز (ذهبي)، وضعان ---------- */
:root {
    --bg: #fbf8f4;
    --surface: #ffffff;
    --ink: #1c1917;
    --muted: #78716c;
    --line: #ece6df;
    --primary: #cf5126;
    --on-primary: #ffffff;
    --accent: #e0643a;
    --accent-soft: #fdece4;
    --accent-text: #b0401a;
    --ok: #2f855a;
    --ok-bg: #eaf5ee;
    --bad: #be1e48;
    --bad-bg: #fdecf0;
    --shadow: 0 1px 2px rgba(60, 30, 15, .05), 0 18px 40px -16px rgba(150, 70, 30, .22);
    --ease: cubic-bezier(.16, 1, .3, 1);
}
:root[data-theme="dark"] {
    --bg: #171311;
    --surface: #201a17;
    --ink: #f5efea;
    --muted: #a8998f;
    --line: #332b26;
    --primary: #ff8a5c;
    --on-primary: #2a0f05;
    --accent: #ff8a5c;
    --accent-soft: #3a231a;
    --accent-text: #ffa77f;
    --ok: #5fcf94;
    --ok-bg: #14291f;
    --bad: #ff7b8a;
    --bad-bg: #2e1a1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 18px 40px -16px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
    font-family: 'Geist', 'IBM Plex Sans Arabic', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100dvh;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s, color .3s;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.mono { font-family: 'Geist Mono', ui-monospace, monospace; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.shell { width: min(1160px, 100% - 48px); margin-inline: auto; }

/* ---------- الشريط العلوي ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.brand-name { font-weight: 700; line-height: 1.2; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.controls { display: flex; align-items: center; gap: 10px; }

.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.seg button { padding: 5px 14px; border-radius: 999px; font-size: .82rem; font-weight: 600; color: var(--muted); transition: background-color .2s, color .2s; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--ink); transition: transform .2s var(--ease), border-color .2s; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(.94); }

/* ---------- أزرار ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 14px 26px; border-radius: 12px; font-weight: 700; background: var(--primary); color: var(--on-primary); transition: transform .2s var(--ease), box-shadow .2s, opacity .2s; }
.btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink); box-shadow: none; }
.link-btn { color: var(--muted); font-size: .9rem; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; padding: 8px 4px; }
.link-btn:hover { color: var(--ink); }
.link-btn:disabled { opacity: .4; pointer-events: none; }

.screen { animation: rise .5s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- الصفحة الرئيسية ---------- */
.home { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: clamp(40px, 7vw, 96px); padding: clamp(40px, 8vw, 96px) 0; align-items: start; }
.eyebrow { display: inline-flex; align-items: center; gap: 10px; font-size: .78rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-text); }
.eyebrow::before { content: ""; width: 28px; height: 2px; background: var(--accent); }
h1 { font-size: clamp(2rem, 4.4vw, 3.4rem); line-height: 1.25; font-weight: 700; margin: 20px 0; max-width: 16ch; }
.lead { color: var(--muted); font-size: 1.08rem; max-width: 46ch; margin-bottom: 32px; }
.cta-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.facts { display: flex; flex-wrap: wrap; gap: 0; margin-top: 48px; border-top: 1px solid var(--line); }
.facts div { padding: 16px 28px 0 0; margin-inline-end: 28px; }
.facts div + div { border-inline-start: 1px solid var(--line); padding-inline-start: 28px; margin-inline-start: 0; }
.facts b { display: block; font: 600 1.5rem/1.2 'Geist Mono', ui-monospace, monospace; }
.facts span { font-size: .84rem; color: var(--muted); }

.levels h2 { font-size: 1rem; font-weight: 700; }
.levels p { color: var(--muted); font-size: .9rem; margin: 4px 0 18px; }
.level-list { list-style: none; border-top: 1px solid var(--line); }
.level-row { width: 100%; display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 16px; padding: 20px 4px; border-bottom: 1px solid var(--line); text-align: start; transition: padding .3s var(--ease), background-color .2s; animation: rise .5s var(--ease) both; animation-delay: calc(var(--i) * 70ms + 120ms); }
.level-row:hover { padding-inline: 14px; background: var(--surface); }
.level-row:active { transform: scale(.99); }
.level-code { font-size: 1.7rem; font-weight: 600; color: var(--ink); }
.level-name { font-weight: 700; display: flex; align-items: center; gap: 10px; }
.level-desc { font-size: .85rem; color: var(--muted); }
.tag { font-size: .7rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--accent); color: #1a1405; }
.level-row .ico { color: var(--muted); transition: transform .3s var(--ease), color .2s; }
.level-row:hover .ico { transform: translateX(-4px); color: var(--accent-text); }

/* ---------- شاشة الاختبار ---------- */
.stage { width: min(680px, 100%); margin-inline: auto; padding: 40px 0 72px; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; font-size: .9rem; color: var(--muted); }
.meta b { color: var(--ink); font-weight: 600; }
.chip { font-size: .78rem; font-weight: 600; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); }
.home-btn { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); padding: 6px 4px; }
.home-btn:hover { color: var(--ink); }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-bottom: 48px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .5s var(--ease); }

.q-label { font-size: .82rem; font-weight: 600; color: var(--accent-text); letter-spacing: .08em; margin-bottom: 12px; }
.sentence { direction: ltr; text-align: left; font-size: clamp(1.45rem, 3.6vw, 2.1rem); line-height: 1.5; font-weight: 500; letter-spacing: -.01em; }
.sentence.def { font-size: clamp(1.15rem, 2.6vw, 1.45rem); color: var(--muted); }
.blank { display: inline-block; min-width: 4.5ch; height: 1em; vertical-align: -.12em; margin-inline: .12em; border-bottom: 3px solid var(--accent); transition: background-color .3s; }
.blank.on { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.hint { margin-top: 18px; color: var(--muted); }
.hint b { color: var(--ink); font-weight: 600; }

.audio { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 36px 0 8px; }
.play { width: 60px; height: 60px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; transition: transform .2s var(--ease), box-shadow .2s; }
.play:hover { box-shadow: var(--shadow); transform: scale(1.05); }
.play:active { transform: scale(.95); }
.play .ico { width: 26px; height: 26px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .88rem; font-weight: 600; transition: border-color .2s, transform .2s var(--ease); }
.pill:hover { border-color: var(--ink); }
.pill:active { transform: scale(.97); }
.status { min-height: 1.6em; font-size: .85rem; color: var(--muted); margin-bottom: 20px; }

.answer { width: 100%; direction: ltr; text-align: left; background: transparent; border: 0; border-bottom: 2px solid var(--line); padding: 10px 0 12px; font-size: 1.9rem; font-weight: 600; letter-spacing: .01em; outline: none; transition: border-color .2s; }
.answer::placeholder { font-family: 'IBM Plex Sans Arabic', sans-serif; font-size: 1.05rem; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.answer:focus { border-color: var(--accent); }
.answer:disabled { color: var(--muted); }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 24px; flex-wrap: wrap; }

.feedback { margin-top: 32px; padding: 22px 24px; border-radius: 16px; border: 1px solid; animation: rise .4s var(--ease) both; }
.feedback.ok { background: var(--ok-bg); border-color: var(--ok); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.fb-head { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 14px; }
.ok .fb-head { color: var(--ok); }
.bad .fb-head { color: var(--bad); }
.reveal { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 0; border-block: 1px solid color-mix(in srgb, currentColor 0%, var(--line)); border-color: var(--line); }
.reveal-en { direction: ltr; display: flex; align-items: baseline; gap: 12px; }
.reveal-en strong { font-size: 1.6rem; font-weight: 600; }
.reveal-en span { font-size: .9rem; color: var(--muted); }
.reveal-ar { font-weight: 700; }
.fb-sentence { direction: ltr; text-align: left; margin: 14px 0 20px; color: var(--muted); font-size: .95rem; }
.fb-sentence b { color: var(--ink); font-weight: 600; }
.feedback .btn { width: 100%; }

/* ---------- النتيجة ---------- */
.result { width: min(760px, 100%); margin-inline: auto; padding: 48px 0 80px; }
.result-head { display: grid; grid-template-columns: auto 1fr; gap: clamp(24px, 5vw, 56px); align-items: end; padding-bottom: 32px; border-bottom: 1px solid var(--line); }
.big-code { font-size: clamp(4.5rem, 14vw, 8rem); font-weight: 600; line-height: .9; letter-spacing: -.04em; position: relative; padding-bottom: 14px; }
.big-code::after { content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 4px; background: var(--accent); border-radius: 2px; }
.result h2 { font-size: clamp(1.4rem, 3vw, 2rem); line-height: 1.3; margin-bottom: 8px; }
.result .summary { color: var(--muted); max-width: 48ch; }
.score { display: flex; align-items: baseline; gap: 10px; margin: 28px 0; }
.score b { font-size: 2.2rem; font-weight: 600; }
.score span { color: var(--muted); }
.mastery { display: grid; gap: 14px; margin-bottom: 44px; }
.m-row { display: grid; grid-template-columns: 110px 1fr 52px; align-items: center; gap: 16px; font-size: .9rem; }
.m-bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.m-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 8px; transition: width .9s var(--ease); }
.m-row .mono { text-align: end; color: var(--muted); }
.review h3 { font-size: 1rem; margin-bottom: 12px; }
.review-list { list-style: none; max-height: 420px; overflow-y: auto; border-top: 1px solid var(--line); }
.review-list:empty::after { content: "لا توجد كلمات للمراجعة بعد."; display: block; padding: 24px 0; color: var(--muted); }
.review-item { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.review-item.pass .ico:first-child { color: var(--ok); }
.review-item.fail .ico:first-child { color: var(--bad); }
.r-en { font-weight: 600; direction: ltr; unicode-bidi: isolate; }
.r-lv { font-size: .75rem; color: var(--muted); margin-inline-start: 8px; }
.r-ar { font-size: .85rem; color: var(--muted); }
.r-wrong { direction: ltr; text-decoration: line-through; color: var(--bad); font-size: .85rem; margin-inline-end: 8px; }
.result-actions { display: grid; gap: 12px; margin-top: 36px; }
.result-actions .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

#confetti-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }

@media (max-width: 860px) {
    .home { grid-template-columns: 1fr; }
    .shell { width: min(1160px, 100% - 32px); }
    .brand-sub { display: none; }
    .result-head { grid-template-columns: 1fr; align-items: start; }
    .m-row { grid-template-columns: 90px 1fr 46px; gap: 10px; }
}
@media (max-width: 520px) {
    .result-actions .two { grid-template-columns: 1fr; }
    .actions .btn { width: 100%; }
    .facts div { padding-inline-end: 16px; margin-inline-end: 16px; }
    .facts div + div { padding-inline-start: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- لمسة عصرية: خلفية مضيئة، بطاقات كبيرة الزوايا، ألوان منعشة ---------- */
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
    background: radial-gradient(60vw 40vw at 100% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
                radial-gradient(45vw 35vw at -5% 105%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%); }
.topbar { border-bottom-color: transparent; }
.brand-mark { background: var(--accent); color: var(--on-primary); border-radius: 12px; }
.btn { border-radius: 14px; box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--primary) 70%, transparent); }
.btn-ghost { background: var(--surface); box-shadow: none; }
.play { background: var(--primary); box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--primary) 80%, transparent); }
.eyebrow { background: var(--accent-soft); padding: 6px 14px; border-radius: 999px; }
.eyebrow::before { width: 8px; height: 8px; border-radius: 50%; }
h1 { max-width: 14ch; }
.ipill { display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; height: 1.05em; padding: 0 .3em; margin-inline: .08em; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); }
.ipill .ico { width: .66em; height: .66em; stroke-width: 1.8; }
.ipill.solid { background: var(--accent); color: var(--on-primary); }
.facts { border-top: 0; gap: 12px; }
.facts div, .facts div + div { margin: 0; padding: 16px 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: clamp(22px, 4vw, 40px); box-shadow: var(--shadow); }
.stage { padding-top: 28px; }
.progress { margin-bottom: 28px; height: 6px; }
.level-list { border: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.level-row { grid-template-columns: 1fr; align-content: start; gap: 6px; padding: 20px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); }
.level-row:hover { padding: 20px; background: var(--surface); transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.level-code { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--accent-soft); color: var(--accent-text); font-size: 1.25rem; margin-bottom: 8px; }
.level-row .ico { display: none; }
.tag { background: var(--accent); color: var(--on-primary); }
.chip { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.blank { border-bottom-color: var(--accent); }
.answer { border-bottom-width: 3px; }
.feedback { border-radius: 20px; }
.big-code { color: var(--accent-text); }
.pill { background: var(--surface); }
@media (max-width: 420px) { .level-list { grid-template-columns: 1fr; } }

/* ---------- شاشات كبيرة (آيباد وكمبيوتر): مقياس أكبر وتوزيع عريض ---------- */
@media (min-width: 1100px) { html { font-size: 106%; } .shell { width: min(1320px, 100% - 96px); } }
@media (min-width: 1500px) { html { font-size: 112%; } }

.side { display: grid; gap: 20px; align-content: start; }
.dash { display: grid; grid-template-columns: 1fr auto; gap: 20px; padding: 22px 24px; border-radius: 24px; }
.dash-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.dash-num { display: flex; align-items: baseline; gap: 8px; }
.dash-num b { font-size: 2.3rem; line-height: 1.15; font-weight: 600; }
.dash-num span { color: var(--muted); font-size: .9rem; }
.meter { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; margin: 12px 0 6px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 8px; transition: width .9s var(--ease); }
.dash-pct { font-size: .85rem; color: var(--accent-text); font-weight: 600; }
.dash-level { display: grid; justify-items: center; align-content: center; gap: 6px; padding-inline-start: 22px; border-inline-start: 1px solid var(--line); min-width: 100px; }
.lvl-badge { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); font-size: 1.5rem; font-weight: 600; }
.dash-sub { font-size: .78rem; color: var(--muted); text-align: center; }

.level-row .mini { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.level-row .mini .meter { flex: 1; margin: 0; height: 5px; }

.sample { display: none; margin-top: 40px; max-width: 480px; padding: 24px 28px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transform: rotate(-1.2deg); }
.sample .sentence { font-size: 1.35rem; margin-top: 6px; }
.sample-row { display: flex; align-items: center; gap: 14px; margin-top: 18px; color: var(--muted); font-size: .9rem; }
.mini-play { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.mini-play .ico { width: 18px; height: 18px; }

.test-grid { display: grid; gap: 24px; }
.sess { padding: 20px 24px; border-radius: 24px; }
.sess-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.sess-row b { display: block; font-size: 1.7rem; font-weight: 600; line-height: 1.2; }
.sess-row span { font-size: .8rem; color: var(--muted); }
.sess-row div:first-child b { color: var(--ok); }
.sess-row div:nth-child(2) b { color: var(--bad); }
.tips { display: none; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
kbd { font-family: 'Geist Mono', monospace; font-size: .75rem; padding: 2px 8px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); color: var(--ink); margin-inline-end: 6px; }

.res-grid { display: grid; gap: 40px; }
.review-list { max-height: none; }

@media (min-width: 960px) {
    .home { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
    .sample { display: block; }
    h1 { font-size: clamp(2.6rem, 4.6vw, 4.2rem); max-width: 13ch; }
    .stage { width: min(1180px, 100%); }
    .test-grid { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
    .tips { display: flex; }
    .result { width: min(1180px, 100%); }
    .res-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
    .review { position: sticky; top: 24px; }
    .review-list { max-height: 640px; }
    .result-head { grid-template-columns: 1fr; align-items: start; }
}
@media (max-width: 520px) { .dash { padding: 18px; gap: 14px; } .dash-level { padding-inline-start: 14px; min-width: 84px; } .dash-num b { font-size: 1.9rem; } }

.nw { white-space: nowrap; }

@media (min-width: 700px) { .sample { display: block; } }

/* ---------- الكلمات الخاطئة ---------- */
.mistakes { padding: 22px 24px; border-radius: 24px; display: grid; gap: 16px; }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.m-head h2 { font-size: 1rem; }
.m-count { min-width: 36px; height: 36px; padding: 0 10px; border-radius: 12px; display: grid; place-items: center; background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.wchip { display: inline-flex; align-items: baseline; gap: 8px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: .85rem; transition: border-color .2s, transform .2s var(--ease); }
.wchip:hover { border-color: var(--accent); }
.wchip:active { transform: scale(.96); }
.wchip b { font-weight: 600; direction: ltr; }
.wchip span { color: var(--muted); font-size: .8rem; }
.wchip.more { color: var(--muted); }
.m-empty { color: var(--muted); font-size: .9rem; }
.mistakes .btn { width: 100%; }
