:root {
  --abyss: #0E3A5B;
  --abyss-deep: #0A2C46;
  --shelf: #2C8C99;
  --shelf-light: #7FC4CF;
  --sand: #EFE5CF;
  --atlas: #F28C28;
  --atlas-deep: #9A4D00;
  --ink: #14263A;
  --foam: #F7FBFD;
  --line: #D3E2EA;
  --muted: #5B7083;
  --error: #B42318;
  --radius-lg: 22px;
  --radius-md: 14px;
  --font: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  color: var(--foam);
  background-color: var(--abyss);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(127, 196, 207, .22), transparent 60%),
    url(contours.svg);
  background-size: auto, 900px 900px;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; }
:focus-visible { outline: 3px solid var(--atlas); outline-offset: 3px; }

/* ---------- الشريط العلوي والتذييل ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
}
.school { display: flex; align-items: center; gap: 10px; color: var(--sand); }
.school-mark { width: 40px; height: 40px; color: var(--sand); flex: none; }
.school strong { display: block; font-weight: 800; font-size: 1.02rem; line-height: 1.25; }
.school span { display: block; font-size: .85rem; opacity: .8; line-height: 1.2; }
.topbar-title { font-weight: 800; color: var(--shelf-light); font-size: .95rem; }

.credits {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 22px;
  padding: 18px 16px max(16px, env(safe-area-inset-bottom));
  font-size: .82rem;
  color: rgba(239, 229, 207, .75);
  text-align: center;
}

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 4px 16px 8px; }
.screen { animation: enter .35s ease-out both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--foam);
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: 0 18px 40px -22px rgba(0, 0, 0, .55);
}

/* ---------- البطل: الكرة الأرضية ---------- */
.hero { text-align: center; padding: 6px 0 22px; }
.globe {
  position: relative;
  width: min(54vw, 210px);
  aspect-ratio: 1;
  margin: 0 auto 14px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 35% 30%, #3f97b8, #155077 60%, #0b3150);
  box-shadow: 0 0 0 6px rgba(127, 196, 207, .14), 0 0 60px rgba(127, 196, 207, .25);
}
.globe-strip {
  position: absolute; inset: 0 auto 0 0;
  display: flex;
  width: 400%;
  height: 100%;
  direction: ltr;
  animation: spin 46s linear infinite;
}
.globe-strip img { width: 50%; height: 100%; display: block; }
@keyframes spin { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.globe-shade {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, .28), transparent 38%),
              radial-gradient(circle at 50% 50%, transparent 52%, rgba(4, 22, 38, .65) 100%);
}
.title {
  margin: 0;
  font-weight: 800;
  font-size: clamp(2.1rem, 8.4vw, 3.4rem);
  line-height: 1.15;
  color: var(--sand);
  letter-spacing: 0;
}
.subtitle { margin: 6px 0 0; font-size: clamp(1.05rem, 3.6vw, 1.3rem); color: var(--shelf-light); font-weight: 600; }

/* ---------- النموذج ---------- */
.form { display: grid; gap: 18px; }
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field > label, .field > legend { display: block; font-weight: 700; margin-bottom: 8px; padding: 0; }
.field input[type=text] {
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
}
.field input[type=text]:focus { border-color: var(--shelf); outline: none; box-shadow: 0 0 0 4px rgba(44, 140, 153, .18); }
.chips { display: grid; gap: 8px; }
.chips-4 { grid-template-columns: repeat(4, 1fr); }
.chips-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 430px) { .chips-4 { grid-template-columns: repeat(2, 1fr); } }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; padding: 6px 8px;
  border: 2px solid var(--line); border-radius: var(--radius-md); background: #fff;
  text-align: center; line-height: 1.25; transition: border-color .15s, background .15s;
}
.chip b { font-size: 1.05rem; }
.chip small { font-size: .78rem; color: var(--muted); }
.chip input:checked + span { border-color: var(--abyss); background: var(--abyss); color: var(--sand); }
.chip input:checked + span small { color: var(--shelf-light); }
.chip input:focus-visible + span { outline: 3px solid var(--atlas); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 10px 22px; width: 100%;
  border: 0; border-radius: var(--radius-md); cursor: pointer;
  font-weight: 800; font-size: 1.15rem;
}
.btn-primary { background: var(--atlas); color: var(--ink); box-shadow: 0 6px 0 var(--atlas-deep); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--atlas-deep); }
.btn-primary[disabled] { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; color: var(--abyss); border: 2px solid var(--abyss); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: #FDECEA; color: var(--error); font-weight: 600; }

.notice { text-align: center; }
.notice h2 { margin: 0 0 6px; }
.notice p { margin: 0 0 8px; color: var(--muted); }

.loader { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 80px 0; color: var(--sand); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(239, 229, 207, .3); border-top-color: var(--atlas); animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- التعليمات ---------- */
.rules .hello { margin: 0; font-size: 1.35rem; font-weight: 800; }
.rules .meta { margin: 0 0 10px; color: var(--muted); }
.rules h2 { margin: 6px 0 10px; font-size: 1.1rem; color: var(--shelf); }
.rule-list { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.rule-list li { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; }
.rule-list b { display: block; }
.rule-list div { color: var(--muted); font-size: .95rem; line-height: 1.55; }
.rule-list div b { color: var(--ink); font-size: 1.02rem; }
.ri {
  width: 44px; height: 44px; border-radius: 12px; background: #E6F1F5;
  display: grid; place-items: center; color: var(--abyss); font-weight: 800; font-size: 1.2rem;
  background-repeat: no-repeat; background-position: center; background-size: 26px;
}
.ri-timer { background: var(--atlas); color: var(--ink); }
.ri-map { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230E3A5B' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 6l6-2 6 2 6-2v14l-6 2-6-2-6 2z'/%3E%3Cpath d='M9 4v14M15 6v14'/%3E%3C/svg%3E"); }
.ri-tap { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230E3A5B' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M8 12l3 3 5-6'/%3E%3C/svg%3E"); }
.ri-once { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230E3A5B' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M5 12h11M12 6l6 6-6 6'/%3E%3C/svg%3E"); transform: scaleX(-1); }
.ri-wifi { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230E3A5B' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2 9a15 15 0 0 1 20 0M5 12.5a10 10 0 0 1 14 0M8.5 16a5 5 0 0 1 7 0'/%3E%3Ccircle cx='12' cy='19.5' r='1' fill='%230E3A5B'/%3E%3C/svg%3E"); }

/* ---------- السؤال ---------- */
.quiz-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin-bottom: 12px; }
.qcount { color: var(--sand); line-height: 1; text-align: center; min-width: 52px; }
.qcount span { display: block; font-size: 2rem; font-weight: 800; }
.qcount small { font-size: .8rem; opacity: .8; }
.route { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; direction: rtl; }
.route i { height: 8px; border-radius: 4px; background: rgba(239, 229, 207, .18); }
.route i.done { background: var(--shelf-light); }
.route i.now { background: var(--atlas); }
.timer { position: relative; width: 66px; height: 66px; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; }
.t-bg { stroke: rgba(239, 229, 207, .18); }
.t-fg { stroke: var(--sand); stroke-linecap: round; stroke-dasharray: 169.65; stroke-dashoffset: 0; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.7rem; font-weight: 800; color: var(--sand); }
.timer.low .t-fg { stroke: var(--atlas); }
.timer.low span { color: var(--atlas); animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.14); } }

.qcard { padding: 12px 12px 14px; position: relative; }
.qtype {
  position: absolute; top: 20px; inset-inline-start: 20px; z-index: 1;
  padding: 2px 12px; border-radius: 999px; background: rgba(14, 58, 91, .88); color: var(--sand);
  font-size: .8rem; font-weight: 700;
}
.map { aspect-ratio: 3 / 2; width: min(100%, calc(46vh * 1.5)); margin: 0 auto; border-radius: 12px; overflow: hidden; background: #d4ebf7; border: 1px solid var(--line); }
.map svg { width: 100%; height: 100%; display: block; }
.prompt { margin: 12px 4px 0; font-size: clamp(1.15rem, 4.4vw, 1.45rem); line-height: 1.45; font-weight: 800; text-align: center; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.opt {
  min-height: 64px; padding: 8px 10px;
  border: 0; border-radius: var(--radius-md);
  background: var(--foam); color: var(--ink);
  font-weight: 700; font-size: clamp(1rem, 4vw, 1.15rem); line-height: 1.3;
  box-shadow: 0 5px 0 #A9C3D1;
  cursor: pointer; touch-action: manipulation;
  transition: transform .08s, box-shadow .08s, background .12s;
}
.opt:active { transform: translateY(3px); box-shadow: 0 2px 0 #A9C3D1; }
.opt.picked { background: var(--atlas); box-shadow: 0 5px 0 var(--atlas-deep); }
.options.locked .opt:not(.picked) { opacity: .55; }
.options.locked .opt { pointer-events: none; }
.swap { animation: swap .18s ease-out both; }
@keyframes swap { from { opacity: .3; } to { opacity: 1; } }

/* ---------- النتيجة ---------- */
.result { text-align: center; }
.medal { position: relative; width: 168px; height: 168px; margin: 4px auto 6px; }
.medal svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.medal circle { fill: none; stroke-width: 11; }
.m-bg { stroke: #E3EEF3; }
.m-fg { stroke: var(--atlas); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 1.4s cubic-bezier(.2, .8, .2, 1); }
.medal-score { position: absolute; inset: 0; display: grid; place-content: center; line-height: 1; }
.medal-score b { font-size: 3.4rem; font-weight: 800; color: var(--abyss); }
.medal-score span { font-size: .95rem; color: var(--muted); margin-top: 6px; }
.result h2 { margin: 6px 0 0; font-size: 1.7rem; }
.r-name { margin: 2px 0 0; font-size: 1.15rem; font-weight: 700; color: var(--shelf); }
.r-meta { margin: 0; color: var(--ink); font-weight: 600; }
.r-sub { margin: 4px 0 16px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stats div { background: #EEF5F8; border-radius: var(--radius-md); padding: 10px 6px; }
.stats dt { font-size: .82rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.5rem; font-weight: 800; color: var(--abyss); }
.r-note { margin: 16px 0 0; font-size: .85rem; color: var(--muted); }

/* ---------- العد التنازلي والتنبيهات ---------- */
.countdown {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-content: center; text-align: center;
  background: rgba(10, 44, 70, .94); color: var(--sand);
}
.countdown span { font-size: 9rem; font-weight: 800; line-height: 1; animation: pop .9s ease-out both; }
.countdown p { margin: 8px 0 0; font-size: 1.3rem; color: var(--shelf-light); }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }
.toast {
  position: fixed; z-index: 30; top: max(12px, env(safe-area-inset-top)); inset-inline: 16px;
  max-width: 520px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--sand); text-align: center; font-weight: 700;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 15; }

@media (min-width: 760px) {
  main { padding-top: 10px; }
  .card { padding: 28px; }
  .qcard { padding: 14px; }
  .opt { min-height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
