:root {
  --bg: #070a24;
  --bg-glow: #141a52;
  --surface: #0f1438;
  --surface-2: #161d4d;
  --border: rgba(160, 176, 255, 0.16);
  --border-strong: rgba(160, 176, 255, 0.32);
  --accent: #e9b949;
  --accent-soft: rgba(233, 185, 73, 0.14);
  --text: #f3f5ff;
  --muted: #959cc8;
  --ok: #22b26b;
  --bad: #e5484d;
  --pending: #f0a020;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "Noto Sans Arabic", "Noto Kufi Arabic", Tahoma, system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), var(--bg) 70%) fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.screen { display: none; min-height: 100vh; padding: 24px; padding-top: max(24px, env(safe-area-inset-top)); }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

.card {
  width: 100%; max-width: 460px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 28px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}

/* ---------- البداية ---------- */
.emblem {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 30px; font-weight: 800; letter-spacing: 0.5px; direction: ltr;
  color: var(--accent);
  border: 2px solid var(--accent);
  background: radial-gradient(circle at 50% 35%, #232b72, #0d1240);
  box-shadow: 0 0 0 6px var(--accent-soft);
  margin-bottom: 6px;
}
h1 { font-size: clamp(26px, 6vw, 34px); font-weight: 800; color: var(--text); }
h2 { font-size: 26px; font-weight: 800; }
.sub { color: var(--muted); font-size: 15px; margin-top: -6px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: #ff9a9e; font-size: 14px; max-width: 380px; line-height: 1.7; }

.actions { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

.rules {
  width: 100%; margin-top: 10px; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px; text-align: start;
}
.rules div { display: flex; justify-content: space-between; gap: 16px; font-size: 13.5px; line-height: 1.6; }
.rules dt { color: var(--muted); white-space: nowrap; }
.rules dd { color: var(--text); text-align: end; }

/* ---------- الأزرار ---------- */
.btn {
  border: 1px solid transparent; border-radius: 12px;
  padding: 13px 28px; font-size: 16px; font-weight: 700;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, opacity 0.15s;
}
.btn.primary { background: var(--accent); color: #1a1530; }
.btn.primary:hover:not(:disabled) { background: #f2c75e; }
.btn.primary:active:not(:disabled) { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn.danger { background: transparent; color: #ffb1b4; border-color: rgba(229, 72, 77, 0.55); }
.btn.danger:hover:not(:disabled) { background: rgba(229, 72, 77, 0.12); }
.btn.small { padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- اللعب ---------- */
#gameScreen.active { justify-content: flex-start; }
.topbar { width: 100%; max-width: 1100px; display: flex; align-items: center; gap: 10px; }
.lifelines { display: flex; gap: 8px; margin-inline-end: auto; }
.ll {
  min-width: 76px; height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 14px; font-weight: 700;
  transition: border-color 0.15s, background 0.15s;
}
.ll:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.ll:disabled { opacity: 0.35; text-decoration: line-through; cursor: not-allowed; }
#ladderToggle { display: none; }

.game-body { width: 100%; max-width: 1100px; display: flex; gap: 24px; flex: 1; align-items: flex-start; margin-top: 20px; }
.stage { flex: 1; display: flex; flex-direction: column; gap: 18px; align-items: stretch; }

.status { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; }
.prize-tag { color: var(--accent); font-weight: 800; font-size: 18px; }

.timer {
  --p: 1;
  position: relative; width: 58px; height: 58px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), rgba(160, 176, 255, 0.15) 0);
  transition: background 0.3s;
}
.timer::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--bg); }
.timer span { position: relative; font-size: 19px; font-weight: 800; color: var(--text); }
.timer.low { background: conic-gradient(var(--bad) calc(var(--p) * 360deg), rgba(229, 72, 77, 0.18) 0); }
.timer.low span { color: #ff9a9e; }

.question-box {
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
  padding: 28px 24px; min-height: 120px;
  display: grid; place-items: center; text-align: center;
  font-size: clamp(18px, 4vw, 23px); font-weight: 600; line-height: 1.7;
}

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer {
  display: flex; gap: 12px; align-items: center; text-align: start;
  padding: 15px 18px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 16.5px; line-height: 1.5;
  transition: border-color 0.15s, background 0.15s;
}
.answer .letter {
  flex: none; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px;
}
.answer:hover:not(.gone) { border-color: var(--accent); background: var(--surface-2); }
.answer.selected { background: rgba(240, 160, 32, 0.18); border-color: var(--pending); }
.answer.selected .letter { background: var(--pending); color: #1a1530; }
.answer.correct { background: rgba(34, 178, 107, 0.2); border-color: var(--ok); animation: flash 0.45s 3; }
.answer.correct .letter { background: var(--ok); color: #fff; }
.answer.wrong { background: rgba(229, 72, 77, 0.18); border-color: var(--bad); }
.answer.wrong .letter { background: var(--bad); color: #fff; }
.answer.gone { visibility: hidden; }
@keyframes flash { 50% { background: rgba(34, 178, 107, 0.4); } }

.message { min-height: 26px; font-size: 17px; font-weight: 600; text-align: center; color: var(--muted); }
.message.ok { color: #5fe0a0; }
.message.bad { color: #ff9a9e; }
#nextBtn { align-self: center; min-width: 200px; }

/* ---------- سلّم الجوائز ---------- */
.ladder {
  width: 230px; padding: 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: rgba(15, 20, 56, 0.9);
  display: flex; flex-direction: column; gap: 2px;
}
.rung {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; border-radius: 8px; font-size: 14.5px; color: var(--muted);
}
.rung .n { font-size: 12.5px; opacity: 0.7; }
.rung .v { font-weight: 600; }
.rung.safe { color: var(--text); }
.rung.safe .v { font-weight: 800; }
.rung.done { color: #6b729e; }
.rung.current { background: var(--accent); color: #1a1530; }
.rung.current .n { opacity: 1; }

/* ---------- النهاية ---------- */
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: 0.5px; }
.win-label { color: var(--muted); font-size: 14px; margin-top: 8px; }
.win-amount { font-size: clamp(40px, 11vw, 64px); color: var(--accent); font-weight: 800; line-height: 1.1; }
.end-card .btn { width: 100%; margin-top: 10px; }

/* ---------- النافذة ---------- */
.modal { position: fixed; inset: 0; background: rgba(3, 5, 20, 0.7); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 10; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 380px; padding: 24px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px; text-align: center;
}
.modal-card h3 { font-size: 18px; font-weight: 800; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bl { width: 22px; color: var(--accent); font-weight: 800; }
.bar { flex: 1; height: 14px; background: rgba(160, 176, 255, 0.12); border-radius: 7px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 7px; transition: width 1s; }
.bp { width: 44px; text-align: left; font-size: 14px; color: var(--muted); }
.friend { line-height: 1.9; font-size: 16.5px; }

/* ---------- الموبايل ---------- */
@media (max-width: 760px) {
  .screen { padding: 16px; }
  .card { padding: 28px 20px; }
  .answers { grid-template-columns: 1fr; }
  .game-body { margin-top: 14px; }
  #ladderToggle { display: inline-block; }
  .ladder {
    display: none; position: fixed; top: 64px; left: 12px; z-index: 5; width: 210px;
    box-shadow: var(--shadow);
  }
  .ladder.open { display: flex; }
  .ll { min-width: 0; height: 36px; padding: 0 10px; font-size: 13px; }
  .topbar { gap: 6px; }
  .topbar .btn.small { padding: 7px 10px; font-size: 13px; }
  .rules div { flex-direction: column; gap: 2px; }
  .rules dd { text-align: start; }
}
