:root {
  --bg: #EEF4FB; --surface: #FFFFFF; --ink: #15176E; --muted: #4A5482; --line: #D5E0EF;
  --blue: #1F47C9; --on-blue: #FFFFFF; --tint: #E2EFFD; --hero: #14147C; --hero-ink: #FFFFFF;
  --hero-muted: #D3DCF8; --mark: #5CB8F5; --teal: #0B8F8A; --gold: #E2600E;
  --ok: #0B8F6A; --ok-tint: #E1F5EE; --bad: #C2372B; --bad-tint: #FCE9E7;
  --radius: 18px; --shadow: 0 18px 40px -26px rgba(21, 23, 110, .45);
  --ui: "Tajawal", system-ui, sans-serif; --read: "Noto Naskh Arabic", "Tajawal", serif;
  --q-size: 1.2rem; --opt-size: 1.15rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1130; --surface: #141B42; --ink: #E8ECFA; --muted: #A9B3D6; --line: #253064;
    --blue: #8FB0FF; --on-blue: #0C1130; --tint: #1D2C63; --hero: #1A2370; --hero-muted: #C9D3F5;
    --teal: #3CC9C2; --gold: #FF8A3D; --ok: #46D19F; --ok-tint: #12352D; --bad: #FF8A80; --bad-tint: #3A1C24;
    --shadow: 0 18px 40px -24px rgba(0,0,0,.8); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1130; --surface: #141B42; --ink: #E8ECFA; --muted: #A9B3D6; --line: #253064;
  --blue: #8FB0FF; --on-blue: #0C1130; --tint: #1D2C63; --hero: #1A2370; --hero-muted: #C9D3F5;
  --teal: #3CC9C2; --gold: #FF8A3D; --ok: #46D19F; --ok-tint: #12352D; --bad: #FF8A80; --bad-tint: #3A1C24;
  --shadow: 0 18px 40px -24px rgba(0,0,0,.8); color-scheme: dark;
}
.kids { --q-size: 1.35rem; --opt-size: 1.4rem; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 17px; line-height: 1.7; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* Header: navy with an Arabic eight-point-star pattern and faint letters */
.top { position: relative; overflow: hidden; isolation: isolate; color: #FFFFFF;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.09' stroke-width='1.2'%3E%3Crect x='16' y='16' width='24' height='24'/%3E%3Crect x='16' y='16' width='24' height='24' transform='rotate(45 28 28)'/%3E%3Ccircle cx='28' cy='28' r='5'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 56px 56px,
    linear-gradient(120deg, #14147C 0%, #1F2FA6 55%, #0B6F8A 100%); }
.top::after { content: ""; position: absolute; inset: auto 0 0 0; height: 4px; background: linear-gradient(90deg, #E8A23A, #5CB8F5, #0B8F8A); }
.top-letters { position: absolute; z-index: -1; inset-inline-end: -10px; top: 50%; transform: translateY(-50%); font: 700 120px/1 "Reem Kufi", "Tajawal", sans-serif; color: rgba(255,255,255,.07); white-space: nowrap; pointer-events: none; }
.top-row { display: flex; align-items: center; gap: 16px; padding-top: 14px; padding-bottom: 16px; }
.brand { flex: none; display: block; line-height: 0; }
.brand img { height: 44px; width: auto; }
.top-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-inline-start: 16px; border-inline-start: 1px solid rgba(255,255,255,.25); }
.top-kicker { font-size: .82rem; font-weight: 700; color: #F3C77A; letter-spacing: .3px; }
.top-name { font: 700 1.25rem/1.35 "Reem Kufi", "Tajawal", sans-serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { flex: none; font-variant-numeric: tabular-nums; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); padding: 4px 12px; border-radius: 999px; font-size: .95rem; white-space: nowrap; }
.timer[hidden] { display: none; }

/* Start page */
.intro { position: relative; margin: 22px 0 16px; border-radius: 24px; overflow: hidden; background: var(--hero); color: #FFFFFF; box-shadow: var(--shadow); }
.intro-img { aspect-ratio: 2 / 1; max-height: 380px; width: 100%; }
.intro-img img { width: 100%; height: 100%; object-fit: cover; }
.intro-copy { position: relative; padding: 18px 24px 22px; margin-top: -90px; background: linear-gradient(180deg, rgba(20,20,124,0) 0%, rgba(20,20,124,.92) 70px, #14147C 100%); }
.intro-copy .eyebrow { display: inline-block; font-size: .8rem; font-weight: 800; padding: 4px 12px; border-radius: 999px; background: #E8A23A; color: #1A1238; }
.intro-copy h1 { font-family: "Reem Kufi", "Tajawal", sans-serif; font-weight: 700; color: #FFFFFF; margin: 10px 0 4px; }
.intro-copy p { margin: 0; color: #D3DCF8; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 14px 0 0; padding: 0; }
.facts li { display: flex; align-items: center; gap: 6px; font-size: .92rem; font-weight: 700; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); }
.req { color: var(--bad); font-weight: 800; }
.hint { display: block; color: var(--muted); font-size: .85rem; margin: -2px 0 6px; }
.field.wide { grid-column: 1 / -1; }
.field input.invalid, .field select.invalid { border-color: var(--bad); background: var(--bad-tint); }
.form-err { color: var(--bad); font-weight: 700; margin: 12px 0 0; }
.notice { margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--tint); border-inline-start: 4px solid var(--blue); }

/* Finish page (student) */
.done { text-align: center; margin: 26px 0 16px; padding: 30px 20px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.done-badge { font-size: 3rem; line-height: 1; }
.done h1 { font-family: "Reem Kufi", "Tajawal", sans-serif; margin: 10px 0 6px; }
.done .lead { margin: 0 auto 16px; max-width: 560px; }
.sent { display: inline-flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 10px 16px; border-radius: 14px; font-weight: 700; }
.sent.ok { background: var(--ok-tint); color: var(--ok); }
.sent.wait { background: var(--tint); color: var(--blue); }
.sent.fail { background: var(--bad-tint); color: var(--bad); }
.sent-ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #FFFFFF; font-size: .9rem; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid currentColor; border-inline-end-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.wa-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; background: linear-gradient(120deg, #E9FBF0, #F4FFF8); border-color: #BFE9CF; }
.wa-copy h2 { margin: 0 0 4px; }
.wa-step { display: inline-block; margin-bottom: 6px; font-size: .8rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: #25D366; color: #FFFFFF; }
.wa-copy p { margin: 0; color: var(--muted); }
.wa-btn { flex: none; display: inline-flex; align-items: center; gap: 10px; padding: 14px 22px; border-radius: 999px; background: #25D366; color: #FFFFFF; font-weight: 800; font-size: 1.05rem; text-decoration: none; box-shadow: 0 12px 24px -14px #128C4A; }
.wa-btn:hover { background: #1EBE5B; }
button.wa-btn { border: 0; cursor: pointer; font-family: inherit; }
.wa-btn[disabled] { opacity: .6; cursor: wait; }
.wa-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.file-chip { font-size: .82rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #fff; border: 1px solid #BFE9CF; color: #0B6F4A; }
.wa-note { margin: 8px 0 0; font-weight: 700; color: #0B6F4A; }
.wa-note:empty { display: none; }
.admin-bar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px; margin: 16px 0 0; padding: 12px 16px; border-radius: 14px; background: #FFF4E0; border: 2px dashed #E8A23A; color: #8A5A12; font-size: .95rem; text-align: center; }
.admin-bar .btn { padding: 9px 18px; font-size: .95rem; }
.wa-lock { margin: 8px 0 0; font-size: .9rem; font-weight: 700; color: #4A5482; }
.wa-btn:focus-visible { outline: 3px solid var(--mark); outline-offset: 3px; }
.wa-btn svg { width: 26px; height: 26px; }
.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.levels li { display: flex; gap: 14px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.lv-n { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--blue); color: var(--on-blue); font-weight: 800; }
.lv-t { display: flex; flex-direction: column; }
.lv-t span { color: var(--muted); }

/* PDF teacher report: drawn off-screen at A4 width (794px), always light */
.rep-host { position: fixed; top: 0; left: -12000px; width: 794px; z-index: -1; pointer-events: none; }
.rep-block { width: 794px; background: #FFFFFF; color: #15176E; font-family: "Tajawal", sans-serif; font-size: 15px; line-height: 1.6; direction: rtl; }
.rep-head { display: flex; align-items: center; gap: 18px; padding: 22px 40px; color: #FFFFFF; background: linear-gradient(120deg, #14147C, #1F2FA6 60%, #0B6F8A); border-bottom: 4px solid #E8A23A; }
.rep-head img { height: 46px; width: auto; }
.rep-head > div { flex: 1; padding-inline-start: 16px; border-inline-start: 1px solid rgba(255,255,255,.3); }
.rep-kicker { color: #F3C77A; font-weight: 700; font-size: 13px; }
.rep-title { font: 700 22px/1.3 "Reem Kufi", "Tajawal", sans-serif; }
.rep-date { font-size: 13px; color: #D3DCF8; direction: ltr; }
.rep-pad { padding: 18px 40px 8px; }
.rep-pad h3 { font-size: 17px; margin: 10px 0 8px; color: #14147C; border-inline-start: 4px solid #0B8F8A; padding-inline-start: 10px; }
.rep-muted { color: #4A5482; font-size: 13.5px; margin: 0 0 8px; }
.rep-block table { width: 100%; border-collapse: collapse; }
.rep-info th, .rep-info td { border: 1px solid #D5E0EF; padding: 7px 10px; text-align: right; font-size: 14px; }
.rep-info th { background: #EEF4FB; color: #4A5482; font-weight: 700; width: 18%; white-space: nowrap; }
.rep-level { margin: 14px 0; padding: 14px 18px; border-radius: 12px; background: #14147C; color: #FFFFFF; text-align: center; }
.rep-level span { display: block; font-size: 13px; color: #D3DCF8; }
.rep-level strong { display: block; font: 700 24px/1.4 "Reem Kufi", "Tajawal", sans-serif; }
.rep-level em { display: block; font-style: normal; color: #F3C77A; font-weight: 700; }
.rep-level p { margin: 6px 0 0; font-size: 13.5px; color: #D3DCF8; }
.rep-scores td { padding: 7px 8px; border-bottom: 1px solid #D5E0EF; }
.rep-scores td.n, .rep-rubric td.n { white-space: nowrap; font-weight: 700; width: 90px; }
.rep-scores td.b { width: 45%; }
.rep-scores td.b div { height: 9px; border-radius: 9px; background: #D5E0EF; overflow: hidden; }
.rep-scores td.b i { display: block; height: 100%; background: #0B8F8A; }
.rep-writing { white-space: pre-wrap; font-family: "Noto Naskh Arabic", serif; font-size: 16px; line-height: 2; padding: 12px 14px; border-radius: 10px; background: #F6F8FC; border: 1px solid #D5E0EF; min-height: 70px; }
.rep-rubric td { padding: 6px 10px; border: 1px solid #D5E0EF; }
.rep-review th { background: #EEF4FB; color: #4A5482; font-size: 12.5px; text-align: right; padding: 6px 8px; border: 1px solid #D5E0EF; }
.rep-review td { font-family: "Noto Naskh Arabic", serif; font-size: 13.5px; padding: 6px 8px; border: 1px solid #D5E0EF; vertical-align: top; }
.rep-review td.n { font-family: "Tajawal", sans-serif; text-align: center; width: 30px; }
.rep-thumb { float: left; width: 36px; height: 36px; object-fit: cover; border-radius: 6px; border: 1px solid #D5E0EF; margin: 0 0 0 8px; }
.rep-review td.m { text-align: center; width: 28px; font-weight: 800; font-size: 16px; }
.rep-review tr.ok td.m { color: #0B8F6A; }
.rep-review tr.bad td.m { color: #C2372B; }
.rep-review tr.bad td:nth-child(3) { color: #C2372B; }

.progress { height: 6px; background: var(--line); }
.progress span { display: block; height: 100%; width: 0; background: var(--mark); transition: width .3s; }

/* Steps */
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 18px 0 6px; padding: 0; list-style: none; }
.steps li { font-size: .82rem; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.steps li.on { background: var(--blue); color: var(--on-blue); border-color: var(--blue); }
.steps li.done { background: var(--tint); color: var(--ink); }

main { padding: 8px 0 120px; }
h1 { font-size: 1.7rem; line-height: 1.35; margin: 18px 0 6px; }
h2 { font-size: 1.4rem; margin: 10px 0 4px; }
.lead { color: var(--muted); margin: 0 0 18px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 16px; box-shadow: var(--shadow); }
.hero-img { border-radius: 14px; overflow: hidden; margin: 0 0 14px; aspect-ratio: 16 / 9; background: var(--tint); }
.hero-img img { width: 100%; height: 100%; object-fit: cover; }
.hero-img.cover { aspect-ratio: 21 / 8; }

/* Start form */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field label { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.rules { margin: 14px 0 0; padding-inline-start: 20px; color: var(--muted); }
.rules li { margin: 2px 0; }

/* Question */
.q-num { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; border-radius: 50%; background: var(--tint); color: var(--blue); font-weight: 800; font-size: .95rem; margin-inline-end: 8px; flex: none; }
.q-head { display: flex; align-items: flex-start; gap: 0; margin-bottom: 12px; }
.q-text { font-size: var(--q-size); font-weight: 700; font-family: var(--read); line-height: 1.8; }
.q-img { width: 200px; max-width: 60%; aspect-ratio: 1; margin: 0 auto 14px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.q-img img { width: 100%; height: 100%; object-fit: cover; }

.opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.opts.long { grid-template-columns: 1fr; }
.opt { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; font-family: var(--read); font-size: var(--opt-size); text-align: start; transition: border-color .15s, background .15s; }
.opt:hover { border-color: var(--mark); }
.opt:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; }
.opt .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); flex: none; position: relative; }
.opt[aria-checked="true"] { border-color: var(--blue); background: var(--tint); }
.opt[aria-checked="true"] .dot { border-color: var(--blue); }
.opt[aria-checked="true"] .dot::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--blue); }

/* Passage */
.passage { font-family: var(--read); font-size: 1.25rem; line-height: 2.15; }
.passage h3 { font-family: var(--ui); margin: 0 0 8px; font-size: 1.2rem; }
.passage p { margin: 0 0 10px; }

/* Audio */
.audio-box { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.play { display: inline-flex; align-items: center; gap: 10px; border: 0; background: var(--teal); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.play[disabled] { opacity: .45; cursor: not-allowed; }
.play svg { width: 20px; height: 20px; }
.plays-left { color: var(--muted); font-size: .95rem; }
.audio-bar { flex: 1 1 160px; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.audio-bar span { display: block; height: 100%; width: 0; background: var(--teal); }
.audio-missing { color: var(--bad); font-size: .95rem; }

/* Writing */
textarea { width: 100%; min-height: 200px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); font-family: var(--read); font-size: 1.15rem; line-height: 2; resize: vertical; }
.wc { color: var(--muted); font-size: .9rem; margin-top: 6px; }

/* Nav */
.nav { position: fixed; inset-inline: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 5; }
.nav .wrap { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 12px; padding-bottom: 12px; }
.btn { border: 0; border-radius: 999px; padding: 12px 26px; font-weight: 800; cursor: pointer; font-size: 1rem; }
.btn.primary { background: var(--blue); color: var(--on-blue); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn[hidden] { display: none; }
.nav-mid { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.nav-info { color: var(--muted); font-size: .9rem; text-align: center; }
.btn.finish { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; font-size: .92rem; background: var(--surface); color: var(--gold); border: 2px solid var(--gold); }
.btn.finish:hover { background: var(--gold); color: #FFFFFF; }
.btn.finish[hidden] { display: none; }
.btn.finish svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* Results */
.result-level { text-align: center; padding: 26px 18px; border-radius: var(--radius); background: var(--hero); color: var(--hero-ink); margin-bottom: 16px; }
.result-level .lv { font-size: 2rem; font-weight: 800; margin: 4px 0; }
.result-level .sc { color: var(--hero-muted); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: start; }
th { font-size: .9rem; color: var(--muted); font-weight: 700; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar span { display: block; height: 100%; background: var(--teal); }
.review { margin-top: 10px; }
.review li { margin: 6px 0; font-family: var(--read); }
.review .ok { color: var(--ok); }
.review .bad { color: var(--bad); }
details summary { cursor: pointer; font-weight: 800; }
.rubric td:first-child { font-weight: 700; }
.rubric select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.student-writing { white-space: pre-wrap; font-family: var(--read); font-size: 1.1rem; background: var(--bg); border-radius: 12px; padding: 12px; min-height: 60px; }
.bands td, .bands th { font-size: .95rem; }
.bands tr.me td { background: var(--tint); font-weight: 800; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

@media (max-width: 640px) {
  .brand img { height: 34px; }
  .top-row { gap: 12px; }
  .top-title { padding-inline-start: 12px; }
  .top-kicker { font-size: .72rem; }
  .top-name { font-size: 1rem; }
  .top-letters { font-size: 90px; }
  .intro { border-radius: 18px; }
  .intro-copy { padding: 14px 16px 18px; margin-top: -60px; }
  .facts li { font-size: .82rem; }
  .wa-card { flex-direction: column; align-items: stretch; text-align: center; }
  .wa-btn { justify-content: center; }
  h1 { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .opts { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .passage { font-size: 1.15rem; }
  .btn { padding: 12px 18px; }
  .nav-info { font-size: .78rem; }
  .nav .wrap { gap: 8px; }
  .nav-mid { flex-direction: column; gap: 4px; }
  .btn.finish { padding: 7px 12px; font-size: .85rem; }
  .btn.finish svg { width: 16px; height: 16px; }
}
@media print {
  .top, .nav, .progress, .steps, .actions, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .result-level { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .result-level { background: #fff; color: #000; }
  .result-level .sc { color: #333; }
  main { padding: 0; }
  details { display: block; }
  details > * { display: block; }
}
