:root {
  --bg-1: #241047;
  --bg-2: #3b1a78;
  --ink: #1d1530;
  --muted: #6f6787;
  --white: #ffffff;
  --card: #ffffff;
  --red: #d42f3d;
  --blue: #2a6fe0;
  --yellow: #c27c00;
  --green: #0f8a50;
  --accent: #ffcd3c;
  --ok: #0f8a50;
  --bad: #d42f3d;
  --late: #6b5f8e;
  --radius: 18px;
  --shadow: 0 8px 0 rgba(0, 0, 0, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Cairo", system-ui, sans-serif;
  color: var(--white);
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  background-color: var(--bg-1);
  min-height: 100vh;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: 0; }

/* أشكال الخلفية */
.bg-shapes { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-shapes .s { position: absolute; opacity: .07; background: var(--white); animation: float 14s ease-in-out infinite; }
.s1 { width: 160px; height: 160px; border-radius: 50%; top: 8%; left: 6%; }
.s2 { width: 120px; height: 120px; transform: rotate(45deg); bottom: 12%; left: 14%; animation-delay: -4s !important; }
.s3 { width: 0; height: 0; background: none !important; border-left: 90px solid transparent; border-right: 90px solid transparent; border-bottom: 150px solid #fff; top: 55%; right: 5%; animation-delay: -8s !important; }
.s4 { width: 110px; height: 110px; border-radius: 16px; top: 14%; right: 20%; animation-delay: -2s !important; }
@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -24px; } }

/* الشاشات */
.screen { display: none; position: relative; z-index: 1; min-height: 100vh; padding: 24px 16px; }
.screen.active { display: flex; flex-direction: column; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* الرئيسية */
#home { align-items: center; }
.hero { text-align: center; margin: 32px 0 36px; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); font-weight: 900; letter-spacing: -.5px; }
.hero p { color: #d8ccf5; font-size: 1.1rem; margin-top: 6px; }
.logo { display: inline-grid; grid-template-columns: repeat(2, 34px); gap: 8px; margin-bottom: 14px; transform: rotate(-8deg); }
.logo-shape { width: 34px; height: 34px; border-radius: 8px; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.logo-shape.tri { background: var(--red); }
.logo-shape.dia { background: var(--blue); }
.logo-shape.cir { background: var(--yellow); border-radius: 50%; }
.logo-shape.sqr { background: var(--green); }

.standards-grid {
  width: 100%; max-width: 980px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.std-card {
  position: relative; text-align: right;
  background: var(--card); color: var(--ink);
  border-radius: var(--radius); padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
  overflow: hidden;
}
.std-card:hover:not(:disabled) { transform: translateY(-4px); box-shadow: 0 12px 0 rgba(0,0,0,.18); }
.std-card:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.std-num {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: var(--c, var(--blue)); color: #fff; font-weight: 900; font-size: 1.3rem; margin-bottom: 10px;
}
.std-title { display: block; font-weight: 800; font-size: 1.15rem; }
.std-meta { display: block; color: var(--muted); font-size: .92rem; margin-top: 2px; }
.std-best { display: inline-block; margin-top: 8px; font-size: .82rem; font-weight: 700; background: #f2ecff; color: #5a2aa8; padding: 2px 10px; border-radius: 99px; }
.std-card:disabled { opacity: .55; cursor: not-allowed; }
.std-card:disabled .std-num { background: #c9c2d9; }

/* اختيار النموذج */
#sets, #list, #subject { align-items: center; }
#list .standards-grid, #sets .standards-grid { display: flex; flex-wrap: wrap; justify-content: center; }
#list .std-card, #sets .std-card { flex: 0 1 220px; min-width: 160px; }
.home-grid { max-width: 720px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.home-card { padding-block: 34px; }
.home-card .std-num { font-size: 1.6rem; }
.home-card .std-title { font-size: 1.6rem; font-weight: 900; }
.sets-head { width: 100%; max-width: 980px; text-align: center; margin: 12px 0 28px; }
.sets-head .ghost-btn { display: block; margin-bottom: 18px; }
.sets-head h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); font-weight: 900; }
.sets-head p { color: #d8ccf5; font-size: 1.05rem; margin-top: 4px; }
.std-card.set-all { background: var(--accent); }
.std-card.set-all .std-num { background: var(--ink); }
.std-card.set-all .std-meta { color: #5c4a12; }

/* العد التنازلي */
#countdown { align-items: center; justify-content: center; }
.countdown-title { font-size: 1.6rem; font-weight: 800; color: #d8ccf5; margin-bottom: 18px; }
.countdown-num {
  width: 170px; height: 170px; display: grid; place-items: center;
  background: var(--accent); color: var(--ink); font-size: 5rem; font-weight: 900;
  border-radius: 32px; transform: rotate(45deg); box-shadow: var(--shadow);
}
.countdown-num span { transform: rotate(-45deg); display: block; }
.countdown-num.pop { animation: pop .5s ease; }
@keyframes pop { 0% { scale: .6; } 60% { scale: 1.1; } 100% { scale: 1; } }

/* السؤال */
#quiz { max-width: 1100px; margin: 0 auto; width: 100%; gap: 14px; }
.topbar { display: flex; align-items: center; gap: 10px; }
.topbar .pill:first-of-type { margin-inline-start: auto; }
.pill { background: rgba(255,255,255,.14); padding: 6px 16px; border-radius: 99px; font-weight: 800; }
.pill-score { background: var(--ok); }
.ghost-btn { background: rgba(255,255,255,.12); color: #fff; padding: 6px 14px; border-radius: 99px; font-weight: 700; }
.ghost-btn:hover { background: rgba(255,255,255,.22); }

.progress { height: 8px; background: rgba(255,255,255,.14); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }

.question-area { display: flex; align-items: center; gap: 16px; margin-top: 6px; }
.question-card {
  flex: 1; background: var(--card); color: var(--ink);
  border-radius: var(--radius); padding: 24px 26px; box-shadow: var(--shadow);
  min-height: 130px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px;
}
.question-card h2 { font-size: clamp(1.15rem, 2.6vw, 1.7rem); font-weight: 800; line-height: 1.6; text-align: center; white-space: pre-line; }
.q-img { max-width: 100%; max-height: 220px; border-radius: 12px; border: 2px solid #eee; }

.timer { position: relative; width: 96px; height: 96px; flex: 0 0 96px; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-track { fill: rgba(255,255,255,.12); stroke: rgba(255,255,255,.18); stroke-width: 8; }
.timer-ring { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke .3s; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.9rem; font-weight: 900; }
.timer.warn .timer-ring { stroke: var(--red); }
.timer.warn span { color: #ffb3ba; animation: pulse 1s infinite; }
@keyframes pulse { 50% { scale: 1.12; } }

.answers {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: auto;
}
.answer {
  --c: var(--red);
  display: flex; align-items: center; gap: 14px;
  min-height: 92px; padding: 14px 18px;
  background: var(--c); color: #fff; text-align: right;
  font-size: clamp(1rem, 2vw, 1.25rem); font-weight: 800; line-height: 1.5;
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s ease, filter .2s, opacity .25s;
}
.answer:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-3px); }
.answer:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.answer:disabled { cursor: default; }
.answer.c0 { --c: var(--red); }
.answer.c1 { --c: var(--blue); }
.answer.c2 { --c: var(--yellow); }
.answer.c3 { --c: var(--green); }
.answer .shape { flex: 0 0 42px; height: 42px; display: grid; place-items: center; }
.answer .shape svg { width: 34px; height: 34px; fill: #fff; filter: drop-shadow(0 2px 0 rgba(0,0,0,.2)); }
.answer .label { flex: 1; }
.answer .mark { flex: 0 0 auto; font-size: 1.6rem; display: none; }

.answers.locked .answer:not(.correct):not(.chosen) { filter: saturate(.2) brightness(.55); }
.answer.correct { outline: 5px solid #fff; outline-offset: -5px; }
.answer.correct .mark, .answer.chosen.wrong .mark { display: block; }
.answer.chosen.wrong { filter: saturate(.6) brightness(.85); }
.answer.correct { animation: bump .45s ease; }
@keyframes bump { 40% { transform: scale(1.03); } }

.feedback {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-radius: 14px; font-size: 1.25rem; font-weight: 900;
  animation: fadeIn .25s ease;
}
.feedback[hidden] { display: none; }
.feedback.ok { background: var(--ok); }
.feedback.bad { background: var(--bad); }
.feedback.late { background: var(--late); }
.explain {
  background: var(--card); color: var(--ink); border-radius: 14px; padding: 12px 18px;
  line-height: 1.8; animation: fadeIn .25s ease;
}
.explain[hidden] { display: none; }
.explain b { display: block; font-weight: 900; margin-bottom: 2px; }
.explain p { font-weight: 600; font-size: 1.02rem; }
.note { margin-top: 8px; padding: 8px 12px; border-radius: 10px; font-size: .95rem; font-weight: 600; line-height: 1.7; }
.note[hidden] { display: none; }
.note-doubt { background: #fff3d6; color: #6b4600; }
.note-check { background: #e6efff; color: #1d3f80; }
.review-item .rx { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #ddd6ea; color: var(--ink); font-weight: 600; line-height: 1.8; }
.next-btn { background: #fff; color: var(--ink); padding: 8px 22px; border-radius: 12px; font-weight: 900; font-size: 1.05rem; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.next-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }

/* النتيجة */
#results { align-items: center; gap: 22px; }
.results-card {
  width: 100%; max-width: 560px; margin-top: 24px;
  background: var(--card); color: var(--ink); border-radius: 24px; padding: 30px 24px;
  box-shadow: var(--shadow); text-align: center;
}
.results-card h2 { font-size: 1.6rem; font-weight: 900; }
.score-ring { position: relative; width: 190px; height: 190px; margin: 18px auto 10px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-track { fill: none; stroke: #eee8f8; stroke-width: 12; }
.score-fill { fill: none; stroke: var(--ok); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset 1.2s ease; }
.score-center { position: absolute; inset: 0; display: grid; place-content: center; }
.score-center strong { font-size: 2.6rem; font-weight: 900; line-height: 1.1; }
.score-center span { color: var(--muted); font-weight: 700; font-size: 1.1rem; }
.result-message { font-size: 1.15rem; font-weight: 700; color: var(--muted); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.stat { border-radius: 14px; padding: 10px 6px; color: #fff; }
.stat b { display: block; font-size: 1.6rem; font-weight: 900; }
.stat span { font-size: .9rem; font-weight: 700; }
.stat.ok { background: var(--ok); }
.stat.bad { background: var(--bad); }
.stat.late { background: var(--late); }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn { padding: 12px 22px; border-radius: 14px; font-weight: 800; font-size: 1.05rem; box-shadow: 0 5px 0 rgba(0,0,0,.15); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.btn-primary { background: var(--bg-2); color: #fff; }
.btn-light { background: #f2ecff; color: #3b1a78; }

.review { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 12px; padding-bottom: 40px; }
.review[hidden] { display: none; }
.review h3 { font-size: 1.3rem; font-weight: 900; }
.review-item { background: var(--card); color: var(--ink); border-radius: 16px; padding: 16px 18px; box-shadow: 0 5px 0 rgba(0,0,0,.15); }
.review-item .rq { font-weight: 800; line-height: 1.6; }
.review-item .rq small { color: var(--muted); font-weight: 700; margin-inline-end: 6px; }
.review-item .ra { margin-top: 8px; font-weight: 700; font-size: .98rem; }
.review-item .ra.yours { color: var(--bad); }
.review-item .ra.right { color: var(--ok); }
.review-empty { background: var(--card); color: var(--ok); text-align: center; padding: 20px; border-radius: 16px; font-weight: 800; }

@media (max-width: 680px) {
  .answers { grid-template-columns: 1fr; gap: 10px; }
  .answer { min-height: 64px; }
  .question-area { flex-direction: column-reverse; }
  .timer { width: 80px; height: 80px; flex-basis: 80px; }
  .question-card { padding: 18px; min-height: 0; }
  .pill { padding: 5px 12px; font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
