/* لَعِب — تصميم خفيف بلا خطوط أو مكتبات خارجية */
:root {
  --bg: #fff6e5;
  --surface: #ffffff;
  --ink: #2b2140;
  --ink-soft: #5d5470;
  --line: #eadfca;
  --brand: #6c3ce9;
  --brand-ink: #ffffff;
  --sun: #ffb703;
  --mint: #2a9d8f;
  --coral: #e76f51;
  --sky: #3a86ff;
  --good: #1f8a4c;
  --good-bg: #dff5e7;
  --bad: #b3261e;
  --bad-bg: #fde4e1;
  --focus: #ff006e;
  --radius: 22px;
  --shadow: 0 4px 0 rgba(43, 33, 64, 0.12);
  --tap: 56px;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", "Arial", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.125rem;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 16px 16px 32px; outline: none; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); }
h2 { font-size: clamp(1.3rem, 4vw, 1.6rem); }
p { margin: 0 0 .8em; }
code { background: #f1e9d8; padding: 0 .3em; border-radius: 6px; }

.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; inset-inline-start: 8px; top: -60px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 10; }
.skip-link:focus { top: 8px; }

:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* الشريط العلوي */
.topbar {
  display: flex; align-items: center; gap: 12px;
  max-width: 960px; width: 100%; margin: 0 auto; padding: 12px 16px;
}
.logo { font-size: 1.6rem; font-weight: 800; color: var(--brand); text-decoration: none; }
.badge-proto { font-size: .8rem; background: #ffe8a3; color: #6b4e00; padding: 2px 10px; border-radius: 999px; }
.parents-link {
  margin-inline-start: auto; font-size: .95rem; color: var(--ink-soft); text-decoration: none;
  padding: 8px 12px; border-radius: 12px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px;
}
.parents-link:hover { background: #f4ead6; }

.banner { max-width: 928px; margin: 0 auto 8px; background: #ffe8a3; color: #5a4100; padding: 10px 16px; border-radius: 14px; font-size: .95rem; }

.footer { text-align: center; font-size: .85rem; color: var(--ink-soft); padding: 16px; }

/* أزرار */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700;
  min-height: var(--tap); padding: 10px 24px; border-radius: 18px;
  background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  transition: transform .08s ease;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 2px solid var(--line); }
.btn.sun { background: var(--sun); color: #3b2a00; }
.btn.mint { background: var(--mint); }
.btn.small { min-height: 44px; padding: 6px 16px; font-size: 1rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }

/* بطاقات */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 2px solid var(--line); }
.stack > * + * { margin-top: 16px; }

.hero { display: flex; align-items: center; gap: 16px; margin: 8px 0 20px; }
.hero .emoji { font-size: 3rem; }

.daily-card { background: linear-gradient(135deg, #6c3ce9, #9b5de5); color: #fff; border: 0; }
.daily-card h2 { color: #fff; }
.daily-card p { color: #efe7ff; }
.daily-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: .95rem; }
.pill { background: rgba(255,255,255,.18); padding: 2px 12px; border-radius: 999px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 24px 0 12px; }
.chip {
  appearance: none; font: inherit; cursor: pointer; min-height: 48px; padding: 6px 18px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; padding: 0; list-style: none; margin: 0; }
.game-card { display: flex; flex-direction: column; gap: 8px; height: 100%; text-decoration: none; color: inherit; }
a.game-card:hover { border-color: var(--brand); }
.game-card .icon { font-size: 2.6rem; width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; }
.game-card h3 { margin: 0; }
.game-card p { color: var(--ink-soft); margin: 0; font-size: 1rem; }
.game-card .tag { align-self: flex-start; font-size: .8rem; padding: 0 10px; border-radius: 999px; background: #f1e9d8; }
.game-card.soon { opacity: .65; }
.bg-sun { background: #fff0c2; } .bg-mint { background: #d6f2ee; } .bg-coral { background: #fde1d9; } .bg-sky { background: #dbe7ff; }

/* الذاكرة */
.statusbar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; font-weight: 600; }
.statusbar span { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 4px 14px; }
.memory-grid { display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); max-width: 560px; margin: 0 auto; }
.mcard {
  appearance: none; border: 0; cursor: pointer; aspect-ratio: 1; border-radius: 18px; font-size: clamp(1.8rem, 8vw, 2.8rem);
  background: var(--brand); color: #fff; box-shadow: var(--shadow); display: grid; place-items: center; padding: 0;
  transition: transform .25s ease, background .2s ease;
}
.mcard .back { font-size: 1.4rem; opacity: .8; }
.mcard.up { background: var(--surface); border: 3px solid var(--line); transform: rotateY(180deg); }
.mcard.up > span { transform: rotateY(180deg); }
.mcard.matched { background: var(--good-bg); border-color: var(--good); }
.mcard:disabled { cursor: default; }

.level-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

/* الأسئلة */
progress { width: 100%; height: 14px; border-radius: 999px; overflow: hidden; appearance: none; border: 0; background: #f1e9d8; }
progress::-webkit-progress-bar { background: #f1e9d8; }
progress::-webkit-progress-value { background: var(--mint); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--mint); }
.q-cat { display: inline-block; font-size: .9rem; background: #f1e9d8; border-radius: 999px; padding: 0 12px; margin: 12px 0 4px; }
.q-text { font-size: clamp(1.3rem, 4.5vw, 1.7rem); font-weight: 700; margin: 8px 0 16px; }
.options { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }
.option {
  appearance: none; font: inherit; font-size: 1.2rem; font-weight: 600; cursor: pointer; text-align: start;
  min-height: 64px; padding: 12px 18px; border-radius: 18px; border: 3px solid var(--line); background: var(--surface); color: var(--ink);
  display: flex; align-items: center; gap: 12px;
}
.option .key { flex: none; width: 34px; height: 34px; border-radius: 10px; background: #f1e9d8; display: grid; place-items: center; font-size: 1rem; }
.option:hover:not(:disabled) { border-color: var(--brand); }
.option.correct { background: var(--good-bg); border-color: var(--good); }
.option.wrong { background: var(--bad-bg); border-color: var(--bad); }
.option:disabled { cursor: default; }
.feedback { min-height: 2em; font-weight: 700; margin-top: 12px; }
.feedback.good { color: var(--good); } .feedback.bad { color: var(--bad); }

/* النتائج */
.result { text-align: center; }
.stars { font-size: 2.6rem; letter-spacing: 6px; }
.big-number { font-size: 3rem; font-weight: 800; color: var(--brand); }

/* الغرف */
.room-code { font-size: clamp(2.2rem, 10vw, 3.4rem); font-weight: 800; letter-spacing: 6px; direction: ltr; text-align: center; color: var(--brand); background: #f3edff; border-radius: 18px; padding: 8px; font-variant-numeric: tabular-nums; }
.code-input { font: inherit; font-size: 2rem; letter-spacing: 6px; text-align: center; direction: ltr; width: 100%; max-width: 320px; min-height: 64px; border-radius: 16px; border: 3px solid var(--line); padding: 8px; }
.code-input[aria-invalid="true"] { border-color: var(--bad); }
.field-error { color: var(--bad); font-weight: 700; min-height: 1.6em; }
.note { background: #eef6ff; border: 2px dashed #9bbcf5; border-radius: 16px; padding: 12px 16px; font-size: 1rem; color: #1e3a6b; }
.note.warn { background: #fff4d6; border-color: #e6c26a; color: #5a4100; }
.avatars { display: flex; gap: 10px; flex-wrap: wrap; }
.avatar-chip { font-size: 1.1rem; background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 6px 14px; }
.leaderboard { list-style: none; padding: 0; margin: 0; }
.leaderboard li { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-radius: 14px; background: var(--surface); border: 2px solid var(--line); margin-bottom: 8px; font-size: 1.2rem; }
.leaderboard li.first { border-color: var(--sun); background: #fff6d6; }

/* لوحة ولي الأمر */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle input { width: 28px; height: 28px; accent-color: var(--brand); flex: none; }
.toggle label { flex: 1; cursor: pointer; }
.toggle small { display: block; color: var(--ink-soft); }
.list-plain { padding-inline-start: 1.2em; margin: 0; }

/* النافذة */
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: min(520px, calc(100vw - 24px)); width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--ink); }
dialog::backdrop { background: rgba(43, 33, 64, .45); }
.dialog-body { padding: 20px; }
.share-preview { width: 100%; max-width: 320px; display: block; margin: 0 auto 12px; border-radius: 16px; border: 2px solid var(--line); }

/* التحميل والأخطاء */
.loading { display: grid; place-items: center; gap: 12px; padding: 60px 0; color: var(--ink-soft); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 5px solid #eadfca; border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-card { border-color: var(--bad); }

.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* الحركة المخفّضة — من النظام أو من إعداد ولي الأمر */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
.btn-row.center { justify-content: center; }
.section-h { margin-top: 28px; }
main > .card + .card, main > section + section { margin-top: 16px; }

/* ===== مسابقة البناء ===== */
kbd { background: #fff; border: 2px solid var(--line); border-bottom-width: 3px; border-radius: 8px; padding: 0 6px; font-family: inherit; font-size: .9em; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c, #999); border: 2px solid rgba(0,0,0,.25); vertical-align: middle; }
.avatar-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .avatar-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.avatar-btn { appearance: none; font: inherit; font-weight: 700; cursor: pointer; border: 3px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 18px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 110px; }
.avatar-btn[aria-pressed="true"] { border-color: var(--brand); background: #f3edff; box-shadow: 0 0 0 3px #c9b6ff; }
.avatar-btn:disabled { opacity: .45; cursor: not-allowed; }
.avatar-btn small { font-weight: 400; color: var(--ink-soft); font-size: .8rem; }
.avatar-canvas { width: 64px; height: 64px; }
.bg-hud { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.bg-timer { font-weight: 800; font-size: 1.3rem; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 2px 14px; font-variant-numeric: tabular-nums; }
.bg-hint { font-weight: 700; font-size: 1.05rem; }
.bg-stage { position: relative; height: min(68vh, 620px); min-height: 320px; border-radius: 22px; overflow: hidden; border: 3px solid var(--line); background: #bde4ff; touch-action: none; user-select: none; -webkit-user-select: none; }
.bg-stage canvas { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.bg-stage canvas:focus-visible { box-shadow: inset 0 0 0 4px var(--focus); }
.bg-countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(5rem, 25vw, 10rem); font-weight: 900; color: #fff; text-shadow: 0 6px 0 rgba(43,33,64,.35); pointer-events: none; opacity: 0; }
.bg-countdown.show { opacity: 1; animation: pop .5s ease; }
.bg-scores { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .bg-scores { grid-template-columns: 1fr 1fr; } }
.bg-scores li { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 4px 10px; font-size: .95rem; }
.bg-scores li.me { border-color: var(--brand); }
.bg-scores .nm { white-space: nowrap; }
.bg-scores .bar { flex: 1; height: 12px; background: #f1e9d8; border-radius: 999px; overflow: hidden; }
.bg-scores .bar > span { display: block; height: 100%; background: var(--c, var(--mint)); border-radius: 999px; transition: width .3s ease; }
.bg-scores .num { font-variant-numeric: tabular-nums; font-weight: 700; }
.bg-help { color: var(--ink-soft); font-size: .9rem; margin-top: 8px; }
.bg-result { margin-top: 16px; }
.game-card .tag.live { background: #dff5e7; color: var(--good); }
@media (max-width: 640px) { .bg-stage { height: 58vh; min-height: 300px; } }

/* ===== سباق العقبات ===== */
.rc-track { position: relative; height: 26px; margin: 0 4px 8px; }
.rc-line { position: absolute; left: 0; right: 24px; top: 11px; height: 6px; border-radius: 999px; background: #e6dcc6; }
#rc-dots { position: absolute; left: 0; right: 24px; top: 0; bottom: 0; }
.rc-dot { position: absolute; top: 4px; width: 18px; height: 18px; margin-left: -9px; border-radius: 6px; background: var(--c, #999); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .15s linear; }
.rc-dot.me { width: 22px; height: 22px; top: 2px; margin-left: -11px; border-color: var(--ink); z-index: 1; }
.rc-flag { position: absolute; right: 0; top: 0; font-size: 1.1rem; }
.rc-stage { touch-action: manipulation; }
.rc-jump { position: absolute; bottom: 14px; left: 14px; width: 84px; height: 84px; border-radius: 50%; border: 4px solid rgba(255,255,255,.9); background: rgba(108,60,233,.85); color: #fff; font: inherit; font-size: 1.8rem; font-weight: 900; display: grid; place-items: center; line-height: 1; box-shadow: 0 4px 0 rgba(43,33,64,.3); cursor: pointer; touch-action: none; }
.rc-jump span { font-size: .8rem; font-weight: 700; }
.rc-jump:active { transform: translateY(2px); }
.rc-avatars { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
#bg-timer, #rc-timer { direction: ltr; unicode-bidi: isolate; }
@media (max-width: 640px) { .rc-stage { height: 50vh; } }

/* ===== ملاحظات اللاعبين ===== */
.feedback-box { margin-top: 16px; padding-top: 12px; border-top: 2px dashed var(--line); text-align: center; }
.feedback-box p { margin-bottom: 6px; font-weight: 700; }

/* ===== أسئلة جماعية ===== */
.qr-card { min-height: 280px; }
.qr-count { font-size: clamp(4rem, 20vw, 7rem); font-weight: 900; text-align: center; color: var(--brand); margin: 12px 0 0; }
.qr-center { text-align: center; font-weight: 700; }
.option.chosen { border-color: var(--brand); background: #f3edff; }
.qr-who { margin-inline-start: auto; display: inline-flex; gap: 4px; }
.qr-state { color: var(--good); font-weight: 800; min-width: 1.2em; }

/* ===== ذاكرة جماعية ===== */
.mr-turn { text-align: center; font-size: 1.4rem; font-weight: 800; padding: 10px; border-radius: 16px; background: var(--surface); border: 3px solid var(--c, var(--line)); margin-bottom: 10px; }
.mr-turn.mine { background: #fff6d6; border-color: var(--sun); animation: pop .4s ease; }
.memory-grid.mr-wait .mcard:not(.up) { opacity: .75; cursor: not-allowed; }
.bg-scores li.turn { border-color: var(--sun); background: #fffaf0; }

/* ===== اسم اللاعب ===== */
.np-preview { text-align: center; font-size: 1.5rem; margin: 0; }
.np-preview strong { color: var(--brand); }
.np-label { font-weight: 700; margin: 8px 0 4px; }
.np-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.np-chips .chip { min-height: 44px; padding: 4px 14px; }

/* الاسم المكتوب */
.np-typed { border: 2px dashed var(--line, #e5dccb); border-radius: 16px; padding: 12px; margin-block: 8px 14px; }
.np-row { display: flex; gap: 8px; align-items: stretch; }
.np-row input { flex: 1; min-width: 0; min-height: 48px; font: inherit; font-size: 1.1rem; padding: 6px 12px; border: 2px solid var(--ink, #3b2f63); border-radius: 12px; background: #fff; color: #222; }
.np-row input:focus-visible { outline: 3px solid var(--accent, #7c5cff); outline-offset: 2px; }
.np-tip { font-size: .9rem; opacity: .85; margin: 6px 0 0; }
.np-msg { min-height: 1.4em; margin: 6px 0 0; font-weight: 600; }
.np-msg.good { color: #1f7a3a; }
.np-msg.bad { color: #b3261e; }
.np-owned { font-weight: 700; align-self: center; }
