:root{color-scheme:light;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}body{margin:0}img{max-width:100%}
/* Layout: one exam console, centered column: header bar (progress + timer), scene panel, question, three signal buttons. */
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #5b6773;
  --line: #d5dce3;
  --asphalt: #2b3540;
  --accent: #1f5fa8;
  --a: #d7262e; --b: #ee8a12; --c: #1f9a4a;
  --ok: #1f9a4a; --bad: #d7262e;
  --scene: #dfe6ec;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #12171d; --panel: #1b222a; --ink: #e8edf2; --muted: #9aa6b2; --line: #2e3842;
  --asphalt: #0d1116; --accent: #6aa7ec; --scene: #26303a; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #12171d; --panel: #1b222a; --ink: #e8edf2; --muted: #9aa6b2; --line: #2e3842;
  --asphalt: #0d1116; --accent: #6aa7ec; --scene: #26303a; color-scheme: dark }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root[lang="ar"] { --display: "Cairo", "Noto Sans Arabic", Tahoma, sans-serif; --body: "Cairo", "Noto Sans Arabic", Tahoma, sans-serif; }
:root[lang="ar"] .qtext, :root[lang="ar"] .ans .txt { font-size: 1.08em; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { background: transparent; color: var(--ink); border: 0; padding: 8px 14px; min-height: 40px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.settings { display: grid; gap: 12px; padding: 14px; background: var(--bg); border-radius: 8px; }
.settings .row { justify-content: space-between; }
.settings .lbl { font-size: .9rem; color: var(--muted); }
/* 16px minimum on form controls: iOS zooms the page when focusing a smaller one */
select { font: inherit; font-size: 16px; min-height: 40px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); max-width: 100%; }
input[type="checkbox"] { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px 32px; }
.wrap { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; min-width: 0; }
h1, h2 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.6rem); line-height: 1.05; }
h2 { font-size: 1.5rem; }
.sub { color: var(--muted); margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: grid; gap: 14px; min-width: 0; }
.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rule { border-top: 3px solid var(--asphalt); padding-top: 8px; min-width: 0; }
.rule b { display: block; font-family: var(--display); font-size: clamp(1.4rem, 1rem + 2vw, 1.8rem); line-height: 1; font-variant-numeric: tabular-nums; }
.rule span { color: var(--muted); font-size: .8rem; line-height: 1.3; display: block; margin-top: 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px 22px; min-height: 48px; font-weight: 600; }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 11px 18px; min-height: 48px; font-weight: 500; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
label.opt { display: flex; gap: 10px; align-items: center; color: var(--ink); font-size: .95rem; min-height: 40px; cursor: pointer; }
.actions-row > button { flex: 1 1 auto; }

/* intro: title + language on top */
.top { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.top > div:not(.seg) { display: grid; gap: 6px; min-width: 0; }
.side { display: grid; gap: 14px; align-content: start; min-width: 0; }

/* exam console: sticky so progress and timer stay visible while scrolling */
.bar { position: sticky; top: max(8px, env(safe-area-inset-top, 0px)); z-index: 4; background: var(--asphalt); color: #fff; border-radius: 12px; padding: 10px 12px 12px;
  display: grid; grid-template-columns: auto auto minmax(0,1fr) auto; column-gap: 12px; row-gap: 8px; align-items: center; box-shadow: 0 6px 16px rgba(0,0,0,.18); }
.bar .qn { font-family: var(--display); font-size: 1.4rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quit { width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,.25); background: transparent; color: #fff; font-size: 1rem; line-height: 1; display: grid; place-items: center; padding: 0; }
.dots { grid-column: 1 / -1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; }
.dots i { height: 6px; border-radius: 3px; background: rgba(255,255,255,.18); }
.dots i.done { background: rgba(255,255,255,.7); }
.dots i.cur { background: var(--b); }
.examno { font-size: .75rem; opacity: .75; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font-family: var(--display); font-size: 1.6rem; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: end; }
.timer.low { color: #ffb4b4; }
.tbar { grid-column: 1 / -1; height: 4px; background: rgba(255,255,255,.15); border-radius: 2px; overflow: hidden; }
.tbar div { height: 100%; background: var(--b); transition: width 1s linear; }
@media (prefers-reduced-motion: reduce) { .tbar div { transition: none; } }
.scene { background: var(--scene); border-radius: 8px; min-height: 150px; display: grid; place-items: center; padding: 14px; }
.scene { padding: 0; overflow: hidden; }
.scene svg { width: 100%; height: auto; display: block; }
.scene .topic { font-family: var(--display); font-size: 1.1rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.qcard { align-items: start; }
.qside { display: grid; gap: 14px; min-width: 0; }
.qtext { font-size: clamp(1.05rem, 1rem + .5vw, 1.25rem); font-weight: 600; margin: 0; line-height: 1.4; }
.answers { display: grid; gap: 10px; }
.ans { display: grid; grid-template-columns: 52px 1fr; align-items: stretch; min-height: 56px; text-align: start; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 0; overflow: hidden; }
.ans .key { display: grid; place-items: center; color: #fff; font-family: var(--display); font-size: 1.5rem; font-weight: 700; }
.ans .txt { padding: 12px 14px; align-self: center; }
.ans.k0 .key { background: var(--a); } .ans.k1 .key { background: var(--b); } .ans.k2 .key { background: var(--c); }
.ans.sel { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink) inset; }
@media (hover: hover) { .ans:hover { border-color: var(--muted); } .primary:not(:disabled):hover { filter: brightness(1.08); } .ghost:hover { border-color: var(--muted); } }
.actions { display: grid; gap: 6px; }
.actions .primary { width: 100%; }
.actions .hint { font-size: .78rem; text-align: center; }
.feedback { border-inline-start: 4px solid var(--ok); padding: 8px 12px; background: var(--bg); border-start-end-radius: 6px; border-end-end-radius: 6px; }
.feedback.bad { border-color: var(--bad); }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }

/* result */
.score { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.score b { font-family: var(--display); font-size: 4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; border-radius: 999px; padding: 4px 12px; font-weight: 600; color: #fff; }
.pill.ok { background: var(--ok); } .pill.bad { background: var(--bad); }
.review { display: grid; gap: 10px; }
.rv { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 4px; }
.rv .q { font-weight: 600; }
.rv .y { color: var(--bad); } .rv .r { color: var(--ok); }
.rv .why { color: var(--muted); font-size: .9rem; }
.note { color: var(--muted); font-size: .8rem; }

/* motion */
.drive { animation: drive 1.5s cubic-bezier(.2,.7,.3,1) both; }
@keyframes drive { from { transform: translate(var(--dx), var(--dy)); } }
.loop { animation: loop var(--t, 6s) linear infinite; }
@keyframes loop { from { transform: translate(var(--fx), var(--fy)); } to { transform: translate(var(--tx), var(--ty)); } }
.blink { animation: blink .8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.lout { animation: lout .2s 1.1s both; } @keyframes lout { to { opacity: 0; } }
.lin { animation: lin .2s 1.1s both; } @keyframes lin { from { opacity: 0; } }
.bob { animation: bob 1s ease-in-out infinite alternate; } @keyframes bob { to { transform: translateY(-3px); } }
.pulse { animation: pulse 1.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; } @keyframes pulse { 50% { transform: scale(1.25); opacity: .6; } }
.enter { animation: enter .35s ease-out both; } @keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.answers .ans { animation: enter .3s ease-out both; }
.answers .ans:nth-child(2) { animation-delay: .06s; } .answers .ans:nth-child(3) { animation-delay: .12s; }
.ans:active { transform: scale(.98); }
.ans.right { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok) inset; }
.ans.wrong { animation: shake .4s; border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad) inset; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.scene { position: relative; }
.zoom { position: absolute; top: 8px; inset-inline-end: 8px; width: 74px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 6px 4px; display: grid; justify-items: center; gap: 2px; box-shadow: 0 4px 12px rgba(0,0,0,.18); animation: pop .4s .5s cubic-bezier(.3,1.6,.5,1) both; }
.zoom svg { width: 56px; height: 56px; }
.zoom span { font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.hero { border-radius: 8px; overflow: hidden; background: var(--scene); }
.hero svg { display: block; width: 100%; height: auto; }
.resultArt { width: 100%; max-width: 320px; }
#resultArt { border-radius: 8px; overflow: hidden; }
.hero canvas, #resultArt canvas { display: block; width: 100%; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall var(--d) linear var(--w) forwards; }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(720deg); } }

/* ---- responsive ---- */
/* phones: tighter cards, stacked buttons, Validate pinned to the bottom of the screen */
@media (max-width: 599px) {
  body { padding-block: 10px 20px; }
  .card { padding: 16px; border-radius: 12px; }
  .settings { padding: 12px; }
  .actions-row > button { flex-basis: 100%; }
  .qcard { padding-bottom: 0; }
  .actions { position: sticky; bottom: 0; z-index: 3; background: var(--panel); margin-inline: -16px; padding: 10px 16px max(12px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
  .zoom { width: 60px; top: 6px; inset-inline-end: 6px; padding: 4px 4px 3px; }
  .zoom svg { width: 44px; height: 44px; }
  .zoom span { font-size: .55rem; }
  .ans { grid-template-columns: 46px 1fr; }
  .ans .txt { padding: 10px 12px; }
}
@media (max-width: 359px) {
  .top { flex-direction: column; }
  .rules { grid-template-columns: 1fr; }
}
/* wide screens and phones in landscape: two columns, so the whole question fits without scrolling */
@media (min-width: 900px), (min-width: 640px) and (max-height: 540px) and (orientation: landscape) {
  .wrap { max-width: 1120px; }
  #result { width: 100%; max-width: 760px; justify-self: center; }
  .intro { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: auto auto 1fr; column-gap: 28px; padding: 28px; }
  .intro .top { grid-column: 1 / -1; }
  .intro .hero { grid-column: 1; grid-row: 2; }
  .intro .rules { grid-column: 1; grid-row: 3; align-self: start; }
  .intro .side { grid-column: 2; grid-row: 2 / span 2; }
  .qcard { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); column-gap: 24px; padding: 24px; }
  .qcard .scene { position: sticky; top: 120px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .bar { position: static; }
  .qcard .scene { position: relative; top: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .drive, .loop, .blink, .bob, .pulse, .enter, .answers .ans, .ans.wrong, .zoom, .confetti i { animation: none !important; }
  .lout { animation-duration: 0s; animation-delay: 0s; } .lin { animation-duration: 0s; animation-delay: 0s; }
  .confetti { display: none; }
}
