:root {
  --navy: #1e3a64;
  --navy-2: #2a4b7c;
  --slate: #7b8fb5;
  --sky: #a9dcf7;
  --sky-soft: #e8f4fc;
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #18233a;
  --muted: #5f6c82;
  --line: #dde3ee;
  --danger: #b4233a;
  --ok: #1f7a55;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 35, 60, .06), 0 8px 24px rgba(20, 35, 60, .07);
  --ease: cubic-bezier(.22, .8, .24, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}
@media (min-width: 640px) {
  body { background: linear-gradient(160deg, #e9eef6 0%, #f6f8fb 60%); }
  .app { margin: 24px auto; min-height: calc(100vh - 48px); border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
}

/* ───── الترويسة ───── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(12px + env(safe-area-inset-top)) 18px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 50%;
  background: #fff; border: 1px solid var(--line);
  display: grid; place-items: center; flex: none;
  box-shadow: 0 2px 6px rgba(30, 58, 100, .08);
}
.brand-logo img { width: 36px; height: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 15px; color: var(--navy); font-weight: 700; }
.brand-text small { font-size: 12.5px; color: var(--muted); }

.progress { margin-top: 12px; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.progress-meta #progressPct { color: var(--navy); font-weight: 600; }
.progress-track { height: 6px; background: #e6ebf3; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--navy), var(--slate)); border-radius: 99px; transition: width .5s var(--ease); margin-inline-start: 0; }

/* ───── المسرح والانتقالات ───── */
.stage { flex: 1; position: relative; overflow-x: hidden; }
.screen { padding: 26px 20px 120px; animation: enterNext .45s var(--ease) both; }
.screen.back { animation-name: enterBack; }
@keyframes enterNext { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@keyframes enterBack { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen, .screen.back { animation: none; } .progress-fill { transition: none; } }

/* ───── شاشة الترحيب ───── */
.welcome {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: calc(32px + env(safe-area-inset-top)) 24px calc(32px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 60% at 50% 0%, #e3edf9 0%, rgba(227, 237, 249, 0) 70%),
    var(--bg);
}
@media (min-width: 640px) { .welcome { min-height: calc(100vh - 48px); } }
.crest {
  width: 196px; height: 196px; border-radius: 50%;
  background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, .7), 0 0 0 9px var(--line), 0 18px 40px rgba(30, 58, 100, .14);
  animation: crestIn .8s var(--ease) both;
}
.crest img { width: 150px; height: auto; }
@keyframes crestIn { from { opacity: 0; transform: scale(.92) translateY(8px); } to { opacity: 1; transform: none; } }
.welcome .kicker { margin: 30px 0 6px; font-size: 14px; color: var(--slate); font-weight: 600; letter-spacing: .2px; }
.welcome h1 { margin: 0; font-size: 28px; line-height: 1.4; color: var(--navy); font-weight: 700; }
.welcome p.lead { margin: 10px auto 0; max-width: 340px; color: var(--muted); line-height: 1.8; font-size: 15.5px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 22px 0 30px; padding: 0; list-style: none; }
.facts li {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 99px;
  padding: 7px 13px; font-size: 13px; color: var(--ink);
}
.facts svg { width: 16px; height: 16px; stroke: var(--navy-2); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.welcome .btn-primary { width: 100%; max-width: 340px; flex: none; min-height: 56px; }
.welcome .fine { margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.anim-up { animation: up .6s var(--ease) both; }
.d1 { animation-delay: .08s; } .d2 { animation-delay: .16s; } .d3 { animation-delay: .24s; } .d4 { animation-delay: .32s; }
@keyframes up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ───── السؤال ───── */
.q-step { display: inline-block; font-size: 12.5px; font-weight: 600; color: var(--navy-2); background: var(--sky-soft); border-radius: 99px; padding: 4px 11px; }
.q-title { margin: 14px 0 6px; font-size: 23px; line-height: 1.5; color: var(--ink); font-weight: 700; }
.q-hint { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; line-height: 1.7; }

.field-input {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 17px 18px;
  font-size: 17px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field-input::placeholder { color: #9aa5b8; }
.field-input:focus { border-color: var(--navy-2); box-shadow: 0 0 0 4px rgba(42, 75, 124, .12); }
textarea.field-input { min-height: 110px; resize: vertical; line-height: 1.7; }
.other-wrap { margin-top: 12px; animation: up .35s var(--ease) both; }

.error { margin-top: 12px; color: var(--danger); font-size: 14px; display: flex; align-items: center; gap: 6px; min-height: 20px; }
.error:empty { display: none; }

/* بطاقات الاختيار */
.choices { display: grid; gap: 12px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: start;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px;
  min-height: 68px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(20, 35, 60, .04);
  transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
}
.choice:active { transform: scale(.985); }
.choice:hover { border-color: #c4cfe0; }
.choice:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(42, 75, 124, .18); }
.choice .ico {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
  background: var(--sky-soft); color: var(--navy);
  transition: background .2s, color .2s;
}
.choice .ico svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.choice .ico.num { font-weight: 700; font-size: 15px; }
.choice .txt { flex: 1; font-size: 16.5px; font-weight: 600; line-height: 1.5; }
.choice .txt small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.choice .tick {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  border: 2px solid #c9d2e1; display: grid; place-items: center;
  transition: all .2s;
}
.choice .tick svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 3; opacity: 0; transform: scale(.5); transition: all .2s; }
.choice[aria-checked="true"] { border-color: var(--navy); background: #f5f9fe; box-shadow: 0 0 0 3px rgba(30, 58, 100, .08); }
.choice[aria-checked="true"] .ico { background: var(--navy); color: #fff; }
.choice[aria-checked="true"] .tick { background: var(--navy); border-color: var(--navy); }
.choice[aria-checked="true"] .tick svg { opacity: 1; transform: none; }

.choices.two .choice { flex-direction: column; align-items: center; text-align: center; padding: 24px 12px 20px; gap: 12px; }
.choices.two .choice .ico { width: 56px; height: 56px; border-radius: 16px; }
.choices.two .choice .ico svg { width: 28px; height: 28px; }
.choices.two .choice .tick { position: absolute; top: 12px; inset-inline-start: 12px; }

.choices.compact .choice { min-height: 58px; padding: 14px 16px; }
.choices.compact .choice .txt { font-size: 15.5px; }
.choices.compact .choice .ico { width: 38px; height: 38px; border-radius: 11px; }
.choices.compact .choice .ico svg { width: 20px; height: 20px; }

/* ───── شريط التنقل ───── */
.navbar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: rgba(243, 245, 249, .94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 15px;
  min-height: 54px; padding: 0 22px;
  font-size: 16.5px; font-weight: 600;
  cursor: pointer;
  transition: transform .15s, background .2s, opacity .2s, box-shadow .2s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--navy); color: #fff; box-shadow: 0 6px 16px rgba(30, 58, 100, .22); flex: 1; }
.btn-primary:hover { background: var(--navy-2); }
.btn-primary:disabled { opacity: .55; cursor: default; box-shadow: none; }
.btn-ghost { background: #fff; color: var(--navy); border: 1.5px solid var(--line); flex: 0 0 auto; }
.btn-ghost:disabled { opacity: .4; cursor: default; }
.btn-soft { background: var(--sky-soft); color: var(--navy); }
.btn-block { width: 100%; }

/* ───── المراجعة ───── */
.review-list { list-style: none; margin: 0; padding: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(20, 35, 60, .04); }
.review-list li { display: flex; align-items: flex-start; gap: 12px; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.review-list li:last-child { border-bottom: 0; }
.review-list .k { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.review-list .v { font-size: 16px; font-weight: 600; line-height: 1.6; word-break: break-word; }
.review-list .body { flex: 1; min-width: 0; }
.edit-link { background: none; border: 0; color: var(--navy-2); font-size: 13.5px; font-weight: 600; cursor: pointer; padding: 6px 4px; flex: none; }
.edit-link:hover { text-decoration: underline; }
.note-box { margin-top: 16px; display: flex; gap: 10px; align-items: flex-start; background: var(--sky-soft); border-radius: 14px; padding: 13px 14px; font-size: 13.5px; color: var(--navy); line-height: 1.7; }
.note-box svg { width: 18px; height: 18px; flex: none; margin-top: 3px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }

/* ───── الشكر ───── */
.thanks { text-align: center; padding-top: 48px; }
.check-badge {
  width: 96px; height: 96px; margin: 0 auto; border-radius: 50%;
  background: var(--navy); display: grid; place-items: center;
  box-shadow: 0 0 0 10px rgba(30, 58, 100, .08), 0 14px 30px rgba(30, 58, 100, .25);
  animation: pop .6s var(--ease) both;
}
.check-badge svg { width: 46px; height: 46px; stroke: #fff; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .5s .35s ease forwards; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
.thanks h2 { margin: 26px 0 8px; font-size: 25px; color: var(--navy); }
.thanks p { margin: 0 auto; color: var(--muted); line-height: 1.8; max-width: 340px; }
.count-card { margin: 24px auto 26px; max-width: 300px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.count-card b { display: block; font-size: 34px; color: var(--navy); line-height: 1.2; }
.count-card span { font-size: 13.5px; color: var(--muted); }
.thanks .actions .btn { flex: none; }
.thanks .actions { display: grid; gap: 10px; max-width: 340px; margin: 0 auto; }
.signature { margin-top: 34px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 13px; }
.signature img { width: 34px; height: auto; }

.spinner { width: 20px; height: 20px; border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ═════════ ثيم فرايحي ═════════ */
:root {
  --navy: #1d3f72;
  --navy-2: #2563eb;
  --c1: #38bdf8; --c1s: #e0f4fe;   /* سماوي */
  --c2: #f472b6; --c2s: #fde7f3;   /* وردي */
  --c3: #fbbf24; --c3s: #fff4d6;   /* أصفر */
  --c4: #34d399; --c4s: #dcf8ed;   /* نعناعي */
  --c5: #a78bfa; --c5s: #efe9ff;   /* بنفسجي */
  --c6: #fb923c; --c6s: #ffeddc;   /* برتقالي */
  --bg: #fbf9ff;
  --line: #e7e3f3;
  --rainbow: linear-gradient(90deg, #38bdf8, #a78bfa, #f472b6, #fb923c, #fbbf24);
}
body { background: #fbf9ff; }
@media (min-width: 640px) {
  body { background: radial-gradient(60% 50% at 10% 10%, #e0f4fe 0%, transparent 70%), radial-gradient(50% 50% at 90% 20%, #fde7f3 0%, transparent 70%), radial-gradient(60% 50% at 50% 100%, #fff4d6 0%, transparent 70%), #fbf9ff; }
}
.app { background: var(--bg); }

/* الترحيب: فقاعات ملونة ونثار */
.welcome {
  position: relative; overflow: hidden;
  background:
    radial-gradient(42% 30% at 12% 8%, rgba(56, 189, 248, .28) 0%, transparent 70%),
    radial-gradient(40% 28% at 92% 14%, rgba(244, 114, 182, .25) 0%, transparent 70%),
    radial-gradient(45% 30% at 85% 92%, rgba(251, 191, 36, .25) 0%, transparent 70%),
    radial-gradient(40% 30% at 8% 88%, rgba(52, 211, 153, .22) 0%, transparent 70%),
    #fbf9ff;
}
.welcome > * { position: relative; z-index: 1; }
.welcome .confetti { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.crest { box-shadow: 0 0 0 8px rgba(255, 255, 255, .85), 0 0 0 11px transparent, 0 18px 40px rgba(167, 139, 250, .25); position: relative; }
.crest::before { content: ''; position: absolute; inset: -11px; border-radius: 50%; padding: 3px; background: conic-gradient(#38bdf8, #a78bfa, #f472b6, #fb923c, #fbbf24, #34d399, #38bdf8); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
@keyframes spinRing { to { transform: rotate(360deg); } }
.welcome .kicker { color: #db2777; }
.welcome h1 { background: linear-gradient(90deg, #1d3f72, #2563eb 55%, #7c3aed); -webkit-background-clip: text; background-clip: text; color: transparent; }
.facts li:nth-child(1) { background: var(--c1s); border-color: transparent; }
.facts li:nth-child(2) { background: var(--c3s); border-color: transparent; }
.facts li:nth-child(3) { background: var(--c4s); border-color: transparent; }
.facts li:nth-child(1) svg { stroke: #0284c7; }
.facts li:nth-child(2) svg { stroke: #d97706; }
.facts li:nth-child(3) svg { stroke: #059669; }

/* الأزرار */
.btn-primary { background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%); box-shadow: 0 8px 20px rgba(99, 102, 241, .32); }
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8 0%, #6d28d9 100%); }
.btn-ghost { color: #4338ca; }

/* الترويسة وشريط التقدم */
.topbar { border-bottom: 0; box-shadow: 0 1px 0 var(--line); }
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: var(--rainbow); opacity: .9; }
.progress-track { background: #efeaf8; height: 8px; }
.progress-fill { background: var(--rainbow); }
@keyframes shimmer { to { background-position: -200% 0; } }
.progress-meta #progressPct { color: #7c3aed; }
.q-step { background: var(--c5s); color: #6d28d9; }

/* بطاقات الاختيار: لون مختلف لكل بطاقة */
.choice { border-color: var(--line); }
.choice:nth-child(6n+1) { --cc: var(--c1); --cs: var(--c1s); --ct: #0369a1; }
.choice:nth-child(6n+2) { --cc: var(--c2); --cs: var(--c2s); --ct: #be185d; }
.choice:nth-child(6n+3) { --cc: var(--c4); --cs: var(--c4s); --ct: #047857; }
.choice:nth-child(6n+4) { --cc: var(--c3); --cs: var(--c3s); --ct: #b45309; }
.choice:nth-child(6n+5) { --cc: var(--c5); --cs: var(--c5s); --ct: #6d28d9; }
.choice:nth-child(6n+6) { --cc: var(--c6); --cs: var(--c6s); --ct: #c2410c; }
.choice .ico { background: var(--cs); color: var(--ct); }
.choice:hover { border-color: var(--cc); }
.choice[aria-checked="true"] { border-color: var(--cc); background: var(--cs); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc) 25%, transparent), 0 8px 18px color-mix(in srgb, var(--cc) 22%, transparent); }
.choice[aria-checked="true"] .ico { background: var(--cc); color: #fff; }
.choice[aria-checked="true"] .tick { background: var(--cc); border-color: var(--cc); }
.choice[aria-checked="true"] { animation: bounceIn .35s var(--ease); }
@keyframes bounceIn { 0% { transform: scale(.97); } 60% { transform: scale(1.02); } 100% { transform: none; } }
.field-input:focus { border-color: #8b5cf6; box-shadow: 0 0 0 4px rgba(139, 92, 246, .15); }

/* المراجعة */
.review-list li:nth-child(6n+1) .k { color: #0369a1; }
.review-list li:nth-child(6n+2) .k { color: #be185d; }
.review-list li:nth-child(6n+3) .k { color: #047857; }
.review-list li:nth-child(6n+4) .k { color: #b45309; }
.review-list li:nth-child(6n+5) .k { color: #6d28d9; }
.review-list li:nth-child(6n+6) .k { color: #c2410c; }
.edit-link { color: #7c3aed; }
.note-box { background: var(--c3s); color: #7c4a03; }

/* الشكر */
.thanks { position: relative; overflow: hidden; }
.thanks > * { position: relative; z-index: 1; }
.check-badge { background: linear-gradient(135deg, #34d399, #2563eb); box-shadow: 0 0 0 10px rgba(52, 211, 153, .15), 0 14px 30px rgba(37, 99, 235, .3); }
.thanks h2 { color: #7c3aed; }
.count-card { background: linear-gradient(135deg, #fff4d6, #fde7f3); border-color: transparent; }
.count-card b { color: #db2777; }

/* نثار */
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; opacity: .9; animation: fall linear infinite; }
@keyframes fall { 0% { transform: translateY(-20px) rotate(0); } 100% { transform: translateY(110vh) rotate(540deg); } }
.thanks .confetti { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.thanks .confetti i { animation-iteration-count: 2; }
@media (prefers-reduced-motion: reduce) { .confetti, .crest::before { display: none; } .progress-fill { animation: none; } }

/* شريط المعاينة */
.preview-note { margin-top: 14px; background: #fff4d6; color: #7c4a03; border-radius: 12px; padding: 10px 14px; font-size: 13px; line-height: 1.7; max-width: 340px; }

/* حقل عدد الساعات */
.num-wrap { position: relative; max-width: 260px; }
.num-input { font-size: 28px; font-weight: 700; text-align: center; letter-spacing: 1px; padding: 16px 70px 16px 18px; font-variant-numeric: tabular-nums; color: var(--navy); }
.num-input::placeholder { font-size: 18px; font-weight: 400; letter-spacing: 0; }
.num-unit { position: absolute; top: 50%; right: 18px; transform: translateY(-50%); font-size: 15px; font-weight: 600; color: #7c3aed; background: var(--c5s); padding: 4px 10px; border-radius: 99px; pointer-events: none; }
