@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 600; font-display: swap; src: url('/fonts/baloo-bhaijaan-2-arabic-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 800; font-display: swap; src: url('/fonts/baloo-bhaijaan-2-arabic-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'Tajawal'; font-weight: 400; font-display: swap; src: url('/fonts/tajawal-arabic-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Tajawal'; font-weight: 500; font-display: swap; src: url('/fonts/tajawal-arabic-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Tajawal'; font-weight: 700; font-display: swap; src: url('/fonts/tajawal-arabic-700-normal.woff2') format('woff2'); }

:root {
  --bg: #F6F3FF;
  --surface: #FFFFFF;
  --surface-2: #F1EEFB;
  --ink: #23194D;
  --ink-2: #5B5480;
  --line: #E3DDF6;
  --primary: #6C4CF1;
  --primary-ink: #FFFFFF;
  --primary-soft: #ECE7FF;
  --sun: #FFC83D;
  --ok: #17A673;
  --ok-soft: #E3F7EF;
  --bad: #E2475B;
  --bad-soft: #FDECEE;
  --warn: #C77700;
  --warn-soft: #FFF4DE;
  --verbal: #8B5CF6;
  --math: #2E86F5;
  --science: #12A87A;
  --flex: #F2763A;
  --radius: 20px;
  --shadow: 0 6px 24px rgba(52, 33, 140, .08), 0 1px 3px rgba(52, 33, 140, .06);
  --font-display: 'Baloo Bhaijaan 2', 'Tajawal', system-ui, sans-serif;
  --font-body: 'Tajawal', system-ui, 'Segoe UI', 'Noto Sans Arabic', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  background-image: radial-gradient(circle at 10% 0%, #EAE3FF 0, transparent 40%), radial-gradient(circle at 100% 30%, #FFF1CC 0, transparent 30%);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.7;
}
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 8px 16px 40px; outline: none; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.3; margin: 0 0 .4em; }
p { margin: 0 0 .8em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; border-radius: 12px; }
main:focus, main:focus-visible { outline: none; }
.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 10; }
.skip:focus { inset-inline-start: 8px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }
.loading { padding: 80px 0; text-align: center; color: var(--ink-2); }

/* ---------- chrome ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 980px; width: 100%; margin: 0 auto; padding: 14px 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--font-display); font-weight: 800; font-size: 28px; }
.footer { text-align: center; color: var(--ink-2); font-size: 14px; padding: 18px 16px 26px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 26px; border-radius: 999px; border: 2px solid transparent;
  font-family: var(--font-display); font-weight: 800; font-size: 20px; cursor: pointer;
  text-decoration: none; transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 0 #4B2FC4; }
.btn-primary:hover:not(:disabled) { background: #5D3DE6; }
.btn-primary:active { box-shadow: 0 3px 0 #4B2FC4; }
.btn-sun { background: var(--sun); color: #3B2A00; box-shadow: 0 6px 0 #D9A41E; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { min-height: 40px; padding: 6px 16px; font-size: 16px; }
.btn-lg { min-height: 64px; padding: 12px 40px; font-size: 24px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* ---------- home ---------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: center; padding: 24px 0 8px; }
.hero h1 { font-size: clamp(32px, 6vw, 50px); }
.hero h1 em { font-style: normal; color: var(--primary); }
.hero p { font-size: 20px; color: var(--ink-2); max-width: 32em; }
.mascot { width: 100%; max-width: 300px; justify-self: center; animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-1deg); } }

.section-title { font-size: 26px; margin: 28px 0 14px; }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grade {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px 12px; border-radius: var(--radius); border: 3px solid var(--line); background: var(--surface);
  cursor: pointer; box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease;
}
.grade:hover { transform: translateY(-3px); }
.grade .num { font-family: var(--font-display); font-weight: 800; font-size: 54px; line-height: 1; color: var(--c); }
.grade .label { font-weight: 700; font-size: 20px; }
.grade .age { font-size: 15px; color: var(--ink-2); }
.grade[aria-checked="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 9%, white); }
.grade[aria-checked="true"]::after { content: '✓'; position: absolute; top: 10px; inset-inline-end: 14px; width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 700; }
.grade:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.start-row { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 26px 0 8px; }
.notice { padding: 14px 18px; border-radius: 14px; background: var(--warn-soft); color: #6B4500; font-size: 16px; }
.notice.bad { background: var(--bad-soft); color: #8A1C2B; }

.domains { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.domain-card { padding: 18px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); border-top: 6px solid var(--c); }
.domain-card .ico { font-size: 30px; }
.domain-card h3 { font-size: 18px; margin: 6px 0 4px; }
.domain-card p { font-size: 15px; color: var(--ink-2); margin: 0; }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; counter-reset: step; }
.how li { list-style: none; background: var(--surface); padding: 16px 18px; border-radius: 16px; box-shadow: var(--shadow); font-size: 16px; }
.how li::before { counter-increment: step; content: counter(step, arabic-indic); display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 800; margin-inline-end: 8px; }
.how { padding: 0; margin: 0; }

.d-verbal { --c: var(--verbal); }
.d-math { --c: var(--math); }
.d-science { --c: var(--science); }
.d-flex { --c: var(--flex); }
.g-3 { --c: #2E86F5; }
.g-4 { --c: #12A87A; }
.g-5 { --c: #F2763A; }

/* ---------- exam ---------- */
.exam-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 14px; }
.progress { flex: 1; height: 14px; border-radius: 99px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--sun), #FFA53D); border-radius: 99px; transition: width .3s ease; }
.progress-text { font-weight: 700; font-size: 16px; white-space: nowrap; color: var(--ink-2); }

.qcard { background: var(--surface); border-radius: 26px; box-shadow: var(--shadow); padding: 26px; }
.qmeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.qnum { font-family: var(--font-display); font-weight: 800; font-size: 22px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 14px; border-radius: 999px; font-size: 15px; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); }
.passage { background: var(--surface-2); border-inline-start: 5px solid var(--c, var(--primary)); padding: 14px 18px; border-radius: 14px; margin-bottom: 16px; white-space: pre-line; font-size: 19px; }
.stem { font-size: 23px; font-weight: 700; margin-bottom: 20px; white-space: pre-line; line-height: 1.8; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  display: flex; align-items: center; gap: 14px; text-align: start; width: 100%;
  min-height: 68px; padding: 12px 16px; border-radius: 18px; border: 3px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 20px; font-weight: 500; transition: border-color .12s ease, background .12s ease, transform .12s ease;
}
.choice:hover { border-color: color-mix(in srgb, var(--primary) 50%, white); }
.choice .letter { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.choice[aria-checked="true"] { border-color: var(--primary); background: var(--primary-soft); }
.choice[aria-checked="true"] .letter { background: var(--primary); color: #fff; }
.choice .txt { flex: 1; }

.exam-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; }
.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; margin-top: 22px; }
.dot { aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: 16px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.dot.answered { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, white); color: var(--primary); }
.dot.current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.finish-row { display: flex; justify-content: center; margin-top: 22px; }
.kbd-hint { text-align: center; font-size: 14px; color: var(--ink-2); margin-top: 10px; }

/* ---------- results ---------- */
.result-hero { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: center; }
.ring { --p: 0; width: 190px; height: 190px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--primary-soft) 0); }
.ring > div { width: 150px; height: 150px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.ring .big { font-family: var(--font-display); font-size: 48px; font-weight: 800; line-height: 1; }
.ring .small { color: var(--ink-2); font-size: 16px; }
.category { font-size: clamp(30px, 5vw, 42px); }
.category .emoji { display: inline-block; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.stat { padding: 8px 16px; border-radius: 14px; background: var(--surface-2); font-size: 16px; }
.stat b { font-family: var(--font-display); font-size: 22px; margin-inline-end: 4px; }
.stat.ok { background: var(--ok-soft); color: #0B6B49; }
.stat.bad { background: var(--bad-soft); color: #9A1F30; }

.bars { display: grid; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 13em 1fr 3.2em; gap: 12px; align-items: center; }
.bar-row .name { font-weight: 700; font-size: 16px; }
.bar { height: 20px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--c); }
.bar-row .val { font-family: var(--font-display); font-weight: 800; font-size: 18px; text-align: end; }
.tip { margin-top: 18px; padding: 16px 18px; border-radius: 16px; background: var(--primary-soft); font-size: 17px; }
.tip strong { color: var(--primary); }

.review-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 30px 0 14px; }
.toggle { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.toggle button { border: 0; background: transparent; padding: 6px 16px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 15px; }
.toggle button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.review { display: grid; gap: 14px; }
.ritem { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border-inline-start: 6px solid var(--ok); }
.ritem.wrong { border-inline-start-color: var(--bad); }
.ritem .stem { font-size: 19px; margin-bottom: 12px; }
.ritem .passage { font-size: 16px; }
.ropts { display: grid; gap: 6px; margin-bottom: 12px; }
.ropt { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: 17px; }
.ropt .letter { font-weight: 800; width: 26px; text-align: center; }
.ropt.correct { background: var(--ok-soft); color: #0B6B49; font-weight: 700; }
.ropt.chosen-wrong { background: var(--bad-soft); color: #9A1F30; text-decoration: line-through; text-decoration-thickness: 1px; }
.ropt .tag { margin-inline-start: auto; font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.explain { background: #FFF8E5; border-radius: 12px; padding: 12px 14px; font-size: 17px; }
.explain b { color: #8A5A00; }
.status-pill { font-size: 14px; font-weight: 700; padding: 2px 12px; border-radius: 99px; }
.status-pill.ok { background: var(--ok-soft); color: #0B6B49; }
.status-pill.bad { background: var(--bad-soft); color: #9A1F30; }
.actions-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 30px 0 0; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- dialog ---------- */
.dialog { border: 0; border-radius: 24px; padding: 26px; max-width: 440px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(35, 25, 77, .3); color: var(--ink); }
.dialog::backdrop { background: rgba(35, 25, 77, .45); }
.dialog h2 { font-size: 24px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- admin ---------- */
.admin main { max-width: 1180px; }
.admin .topbar { max-width: 1180px; }
.admin body, body.admin { font-size: 16px; }
.admin h1 { font-size: 30px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 18px; }
.tabs button { border: 0; background: var(--surface); padding: 8px 18px; border-radius: 999px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .v { font-family: var(--font-display); font-size: 34px; font-weight: 800; line-height: 1.1; }
.kpi .k { color: var(--ink-2); font-size: 14px; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
td.low { background: var(--bad-soft); color: #9A1F30; font-weight: 700; }
.diffbar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; min-width: 90px; background: var(--surface-2); }
.diffbar span:nth-child(1) { background: #7DD3A8; }
.diffbar span:nth-child(2) { background: #FFC83D; }
.diffbar span:nth-child(3) { background: #F2763A; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin: 8px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-weight: 700; font-size: 14px; }
.field input, .field select, .field textarea { padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); width: 100%; }
.field textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 140px; }
.alert { padding: 12px 16px; border-radius: 12px; margin: 10px 0; font-size: 15px; }
.alert.ok { background: var(--ok-soft); color: #0B6B49; }
.alert.bad { background: var(--bad-soft); color: #8A1C2B; }
.alert.warn { background: var(--warn-soft); color: #6B4500; }
.gen-domains { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.gen-domain { background: var(--surface-2); border-radius: 14px; padding: 14px; border-top: 5px solid var(--c); font-size: 14px; }
.gen-domain .count { font-family: var(--font-display); font-size: 26px; font-weight: 800; }
.gen-domain ul { margin: 6px 0 0; padding-inline-start: 18px; color: var(--ink-2); }
.qrow-stem { max-width: 520px; }
.qrow-stem small { color: var(--ink-2); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; }
.choice-input { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.choice-input input[type=text] { flex: 1; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); }
.login { max-width: 420px; margin: 40px auto; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.detail-choices li.ok { color: var(--ok); font-weight: 700; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero p { margin-inline: auto; }
  .mascot { max-width: 180px; grid-row: 1; }
  .domains { grid-template-columns: 1fr 1fr; }
  .how { grid-template-columns: 1fr; }
  .choices { grid-template-columns: 1fr; }
  .qcard { padding: 18px; border-radius: 20px; }
  .stem { font-size: 20px; }
  .choice { font-size: 18px; min-height: 60px; }
  .palette { grid-template-columns: repeat(5, 1fr); }
  .result-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .stats { justify-content: center; }
  .bar-row { grid-template-columns: 1fr 3em; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .grid2 { grid-template-columns: 1fr; }
  .exam-nav .btn { padding-inline: 16px; }
}
@media (max-width: 420px) {
  .grades { gap: 8px; }
  .grade { padding: 16px 6px; }
  .grade .num { font-size: 42px; }
  .grade .label { font-size: 16px; }
  .domains { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- admin activity ---------- */
.kpi.small-v .v { font-size: 28px; }
.kpi.live { background: linear-gradient(135deg, #ECE7FF, #FFFFFF); }
.pulse { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); margin-inline-end: 8px; vertical-align: middle; box-shadow: 0 0 0 0 rgba(23, 166, 115, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(23, 166, 115, 0); } 100% { box-shadow: 0 0 0 0 rgba(23, 166, 115, 0); } }
.live-pages { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.chart-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.cols { display: flex; align-items: flex-end; gap: 4px; height: 140px; border-bottom: 1px solid var(--line); }
.col { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.col:hover .col-bar { background: #4B2FC4; }
.col-bar { display: block; width: 100%; min-height: 2px; background: var(--primary); border-radius: 4px 4px 0 0; }
.cols-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.hbar { display: grid; grid-template-columns: minmax(9em, 1.4fr) 2fr 3.5em; gap: 10px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.hbar .bar { height: 12px; }
.hbar .bar > span { background: var(--primary); }
.hbar-val { font-weight: 700; text-align: end; }
.kpi table { font-size: 14px; }
