:root {
  --bg-main: #020617;
  --accent: #22d3ee;
  --accent-soft: #38bdf8;
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --danger: #fb7185;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --border-soft: rgba(148,163,184,0.5);
  --gold: #d4af37;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background:
    radial-gradient(circle at top, #0f172a 0, #020617 45%, #000 100%),
    linear-gradient(135deg, rgba(56,189,248,0.15), rgba(34,197,94,0.08));
  color: var(--text-main);
  direction: rtl;
}

/* شبكة خفيفة بالخلفية */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(30,64,175,0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,64,175,0.25) 1px, transparent 1px);
  background-size: 52px 52px;
  opacity: 0.18;
  pointer-events: none;
  z-index: -1;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 10px calc(18px + env(safe-area-inset-bottom));
}

/* رأس الموقع */
.app-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(56,189,248,0.9);
  background:
    radial-gradient(circle at 0 0, rgba(34,211,238,0.7), transparent 60%),
    radial-gradient(circle at 100% 100%, rgba(34,197,94,0.5), transparent 65%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 28px rgba(34,211,238,0.9),
    0 0 34px rgba(22,163,74,0.6);
}

.brand-icon span {
  font-size: 20px;
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(1rem, 0.9rem + 0.5vw, 1.4rem);
  letter-spacing: 0.06em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.hud {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 170px;
}

.hud-pill {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34,211,238,0.85);
  background: radial-gradient(circle at top, rgba(34,211,238,0.26), transparent 60%);
  font-size: 0.76rem;
  color: #bae6fd;
}

.hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34,197,94,0.95);
}

.hud-user {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.hud-user span {
  color: #e0f2fe;
  font-weight: 500;
}

/* التقدّم */
.progress {
  margin-bottom: 10px;
}

.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.progress-bar {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #020617;
  border: 1px solid rgba(148,163,184,0.7);
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0;
  transform-origin: right center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #22d3ee, #0ea5e9);
  box-shadow: 0 0 18px rgba(34,211,238,0.9);
  transition: transform 0.35s ease-out;
}

.progress-steps {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.step-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.7);
  background: #020617;
  position: relative;
}

.step-dot::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: linear-gradient(135deg, #22d3ee, #22c55e);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

.step-dot--active::after {
  opacity: 1;
  transform: scale(1);
}

/* شاشات */
.main {
  margin-top: 6px;
}

.screen {
  display: none;
}

.screen--active {
  display: block;
}

/* بطاقات عامة */
.card {
  border-radius: 18px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  background:
    radial-gradient(circle at top left, rgba(34,211,238,0.16), transparent 55%),
    radial-gradient(circle at bottom right, rgba(34,197,94,0.14), transparent 55%),
    rgba(15,23,42,0.96);
  box-shadow: 0 0 26px rgba(15,23,42,0.96);
}

/* شاشة البداية */
.intro-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2.2fr);
  gap: 12px;
}

@media (max-width: 800px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .intro-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.intro-text h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: #e0f2fe;
}

.intro-lead {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.9;
}

.intro-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.intro-list li {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
  line-height: 1.8;
}

.intro-list li::before {
  content: "◆";
  font-size: 0.6rem;
  margin-top: 4px;
  color: var(--accent);
}

.form-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.form-field {
  flex: 1 1 220px;
}

.form-field label {
  display: block;
  font-size: 0.84rem;
  margin-bottom: 4px;
}

.form-field input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148,163,184,0.9);
  background: #020617;
  color: var(--text-main);
  font-size: 0.9rem;
}

.field-error {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--danger);
  display: none;
}

.hint {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* أزرار */
.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition:
    transform 0.12s ease-out,
    box-shadow 0.15s ease-out,
    background 0.15s ease-out,
    border-color 0.15s ease-out,
    color 0.15s ease-out;
  white-space: nowrap;
}

.btn--primary {
  background: radial-gradient(circle at top, #22d3ee, #0ea5e9);
  color: #020617;
  box-shadow:
    0 0 18px rgba(34,211,238,0.9),
    0 0 36px rgba(56,189,248,0.7);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 22px rgba(34,211,238,0.95),
    0 0 46px rgba(56,189,248,0.85);
}

.btn--outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(148,163,184,0.85);
}

.btn--outline:hover {
  background: rgba(15,23,42,0.98);
}

.btn--wide {
  flex: 1 1 150px;
}

/* بوستر سينمائي */
.intro-poster {
  display: flex;
  align-items: center;
  justify-content: center;
}

.poster-frame {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(148,163,184,0.7);
  box-shadow:
    0 0 22px rgba(15,23,42,0.95),
    0 0 32px rgba(34,211,238,0.4);
  background: radial-gradient(circle at center, #020617 0, #020617 55%, #000 100%);
}

.poster-bars {
  position: absolute;
  inset-inline: 0;
  height: 12%;
  background: rgba(0,0,0,0.92);
  z-index: 5;
}

.poster-bars--top { top: 0; }
.poster-bars--bottom { bottom: 0; }

.poster-media {
  position: absolute;
  inset: 10%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  perspective: 1000px;
}

/* شخصيات عامة (تستخدم في البوستر والمشهد) */
.poster-character,
.scene-character {
  position: relative;
  width: 46%;
  transform-origin: center bottom;
  animation: float 4s ease-in-out infinite;
}

.poster-character--left,
.scene-character--main {
  transform: perspective(900px) rotateY(-14deg);
}

.poster-character--right,
.scene-character--other {
  transform: perspective(900px) rotateY(14deg);
  animation-delay: 0.8s;
}

/* الرأس */
.char-head {
  position: relative;
  width: 70%;
  margin: 0 auto;
}

.char-face {
  position: relative;
  width: 100%;
  padding-top: 110%;
  border-radius: 60% 60% 52% 52%;
  background: linear-gradient(180deg, #fee2c5, #f59e63);
  box-shadow: 0 4px 10px rgba(15,23,42,0.7);
}

.char-head--male::before,
.char-head--female::before {
  content: "";
  position: absolute;
  inset-inline: -4%;
  top: -8%;
  height: 60%;
  border-radius: 60% 60% 40% 40%;
  background: linear-gradient(90deg, #020617, #111827);
  box-shadow: 0 3px 6px rgba(0,0,0,0.7);
}

.char-head--female::before {
  inset-inline: -6%;
  top: -10%;
}

/* العينان */
.char-eye {
  position: absolute;
  top: 42%;
  width: 16%;
  padding-top: 16%;
  border-radius: 999px;
  background: #111827;
}

.char-eye::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: inherit;
  background: #e5e7eb;
}

.char-eye--left { left: 20%; }
.char-eye--right { right: 20%; }

/* الفم */
.char-mouth {
  position: absolute;
  left: 24%;
  right: 24%;
  bottom: 20%;
  height: 10%;
  border-radius: 0 0 999px 999px;
  background: #111827;
}

.char-mouth--neutral {
  border-radius: 999px;
  height: 6%;
  top: 62%;
  border-bottom: 3px solid #111827;
  background: transparent;
}

.char-mouth--smile {
  border-radius: 999px;
  height: 7%;
  top: 63%;
  border-bottom: 3px solid #111827;
  background: transparent;
}

/* الجسد */
.char-body {
  position: relative;
  width: 80%;
  margin: 6px auto 0;
  padding-top: 90%;
  border-radius: 34px;
  box-shadow: 0 12px 20px rgba(15,23,42,0.95);
}

.char-body--blue {
  background: linear-gradient(180deg, #22d3ee, #0f766e);
}

.char-body--violet {
  background: linear-gradient(180deg, #6366f1, #1d4ed8);
}

/* ظل */
.char-shadow {
  width: 80%;
  margin: 6px auto 0;
  height: 14px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(0,0,0,0.7), transparent);
  filter: blur(1px);
}

.char-shadow--small {
  width: 70%;
}

/* بطاقة الجهاز (الجهة المقابلة) */
.device-card {
  position: relative;
  width: 90%;
  margin: 10px auto 0;
  padding-top: 65%;
  border-radius: 18px;
  background: linear-gradient(145deg, #020617, #16a34a);
  box-shadow: 0 12px 20px rgba(15,23,42,0.95);
  overflow: hidden;
}

.device-screen {
  position: absolute;
  inset: 10%;
  border-radius: 12px;
  background: radial-gradient(circle at top, rgba(15,23,42,0.96), rgba(15,23,42,0.9));
  border: 1px solid rgba(15,23,42,0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding-inline: 10%;
}

.device-line {
  height: 6px;
  border-radius: 999px;
}

.device-line--1 { background: #22c55e; }
.device-line--2 { background: #16a34a; width: 70%; }
.device-line--3 { background: #4ade80; width: 40%; }

/* تعليق البوستر */
.poster-caption {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 10%;
  text-align: center;
  font-size: 0.75rem;
  color: #e5e7eb;
  text-shadow: 0 2px 4px rgba(0,0,0,0.9);
}

.poster-caption span {
  display: block;
  font-size: 0.7rem;
  color: #bae6fd;
}

/* حركة خفيفة */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* مشغل المشهد */
.scene {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.scene-tag {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.8);
  background: rgba(15,23,42,0.96);
}

.scene-counter {
  color: #cbd5f5;
}

/* شاشة السينما */
.scene-cinema {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(circle at center, #020617 0, #020617 55%, #000 100%);
  /* على الجوال نستخدم 9:16 تقريبًا؛ على العرض الكبير 16:9 عبر max-height */
  width: 100%;
  max-height: min(60vh, 460px);
  aspect-ratio: 9 / 16;
}

@media (min-width: 700px) {
  .scene-cinema {
    aspect-ratio: 16 / 9;
  }
}

.scene-bars {
  position: absolute;
  inset-inline: 0;
  height: 11%;
  background: rgba(0,0,0,0.92);
  z-index: 5;
}

.scene-bars--top { top: 0; }
.scene-bars--bottom { bottom: 0; }

.scene-media {
  position: absolute;
  inset: 11% 4% 16%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  perspective: 1100px;
}

.scene-media-inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* نص المشهد */
.scene-text-area {
  margin-top: 4px;
  font-size: 0.9rem;
  line-height: 1.9;
}

.scene-title {
  margin: 0 0 4px;
  color: #e0f2fe;
  font-size: 0.94rem;
}

.scene-text {
  margin: 0 0 4px;
  color: var(--text-main);
  font-size: 0.86rem;
}

.scene-question {
  margin: 0;
  color: var(--accent-soft);
  font-size: 0.86rem;
  font-weight: 600;
}

/* أسفل المشهد */
.scene-footer {
  margin-top: 4px;
}

.choices-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback {
  margin-top: 6px;
  font-size: 0.84rem;
  border-radius: 10px;
  padding: 7px 9px;
  display: none;
}

.feedback--correct {
  display: block;
  background: rgba(22,163,74,0.22);
  border: 1px solid rgba(34,197,94,0.9);
  color: #bbf7d0;
}

.feedback--wrong {
  display: block;
  background: rgba(185,28,28,0.35);
  border: 1px solid rgba(248,113,113,0.9);
  color: #fee2e2;
}

.status-line {
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* تمييز زر الإجابة */
.btn--correct-active {
  border-color: rgba(34,197,94,0.95) !important;
  box-shadow: 0 0 22px rgba(34,197,94,0.85) !important;
  background: radial-gradient(circle at top, #22c55e, #16a34a) !important;
  color: #022c22 !important;
}

.btn--wrong-active {
  border-color: rgba(248,113,113,0.95) !important;
  box-shadow: 0 0 22px rgba(248,113,113,0.9) !important;
  background: radial-gradient(circle at top, #fb7185, #b91c1c) !important;
  color: #fff7f7 !important;
}

/* الشهادة */
.cert-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.cert-paper {
  position: relative;
  width: min(100%, 780px);
  min-height: 380px;
  background: #ffffff;
  color: #111827;
  border-radius: 16px;
  padding: 24px 24px 28px;
  border: 2px solid var(--gold);
  box-shadow:
    0 0 0 3px rgba(212,175,55,0.25),
    0 20px 52px rgba(15,23,42,0.95);
  overflow: hidden;
}

.cert-paper::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 12px;
  border: 1px solid rgba(212,175,55,0.65);
  pointer-events: none;
}

.cert-watermark {
  position: absolute;
  inset: 18%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.15;
  pointer-events: none;
}

.cert-watermark img {
  max-width: 60%;
  max-height: 100%;
  object-fit: contain;
}

.cert-header {
  position: relative;
  text-align: center;
  margin-bottom: 16px;
}

.cert-logo img {
  max-width: 110px;
  height: auto;
}

.cert-title {
  margin: 8px 0 4px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.cert-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: #4b5563;
}

.cert-body {
  position: relative;
  font-size: 0.9rem;
  line-height: 2;
}

.cert-body p {
  margin: 0 0 6px;
}

.cert-name {
  display: inline-block;
  min-width: 130px;
  padding: 0 4px 2px;
  border-bottom: 1px solid #9ca3af;
  text-align: center;
  font-weight: 700;
}

.cert-footer {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.8rem;
  color: #4b5563;
}

.cert-meta {
  min-width: 190px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cert-sign-line {
  margin-top: 22px;
  border-bottom: 1px solid #9ca3af;
  padding-bottom: 4px;
}

.cert-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.cert-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* طباعة الشهادة فقط */
@media print {
  body {
    background: #ffffff;
  }
  .app {
    padding: 0;
    margin: 0;
  }
  .app-header,
  .progress,
  #screen-intro,
  #screen-scene,
  .cert-actions,
  .cert-note {
    display: none !important;
  }
  #screen-certificate {
    display: block !important;
  }
  .cert-paper {
    box-shadow: none;
  }
}