/*
 * أنماط ألعاب ماروكو — مقاسة لشاشة ذكية في قاعة، لا لهاتف في يد.
 *
 * القياسات كلّها بـclamp() تتبع عرض الشاشة: الشاشة الذكية في الروضة قد تكون
 * ٤٣ بوصة وقد تكون ٧٥، ومقاسٌ ثابت يصلح لواحدة يصير مضحكاً على الأخرى.
 *
 * وكل ما يُلمس ٩٦ بكسل فأكثر: إصبع طفل في الرابعة أعرض من إصبع بالغ وأقلّ
 * دقّة، وزرٌّ بمقاس هاتف يعني نقرات تخطئ فيملّ.
 */

:root {
  --teal: #14776A;
  --teal-d: #0E5C52;
  --sun: #FFC24B;
  --coral: #FF7A59;
  --lilac: #8B7BE8;
  --sky: #4FA3E3;
  --rose: #E4526B;
  --mint: #38C7A0;
  --ink: #172523;
  --ink2: #5E6E6B;
  --paper: #FFFDF9;
  --line: #EDE7DE;
  --r: 26px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: 'Segoe UI', 'Noto Kufi Arabic', 'Tahoma', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  direction: rtl;
  /*
   * لا تحديد ولا قائمة سياق: الطفل يضغط مطوّلاً بلا قصد، فتظهر قائمة النسخ
   * فوق اللعبة ولا يعرف كيف يُزيلها.
   */
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

/*
 * body عمود مرن — لا html.
 * فيقيس المسرح (أو القائمة) ما تبقّى بعد الشريط بدقّة، بدل طرح رقم مقدَّر
 * يقصّ أسفل اللعبة إن اختلف ارتفاع الشريط قليلاً.
 */
body { display: flex; flex-direction: column; }

/* ── خلفية حيّة ────────────────────────────────────────
 *
 * كتل ملوّنة تطوف ببطء. بطيئة عمداً — خلفية سريعة خلف لعبة تشتّت الطفل عن
 * اللعبة نفسها.
 */
body::before, body::after {
  content: ''; position: fixed; border-radius: 50%;
  filter: blur(70px); opacity: 0.5; z-index: 0; pointer-events: none;
}
body::before {
  width: 46vw; height: 46vw; background: #BFE3DB; top: -12vw; right: -8vw;
  animation: drift1 34s ease-in-out infinite alternate;
}
body::after {
  width: 40vw; height: 40vw; background: #FFE0CF; bottom: -14vw; left: -6vw;
  animation: drift2 42s ease-in-out infinite alternate;
}
@keyframes drift1 { to { transform: translate(-9vw, 7vw) scale(1.15); } }
@keyframes drift2 { to { transform: translate(8vw, -6vw) scale(1.1); } }

/* ── الشريط العلوي ─────────────────────────────────── */

.hud {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: clamp(8px, 1.2vw, 18px);
  padding: clamp(10px, 1.4vh, 20px) clamp(14px, 2vw, 32px);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--line);
}

/*
 * الأزرار ٦٨ بكسل فما فوق.
 *
 * كانت ٥٢ على شاشة ١٣٦٦ — مقاس هاتف على شاشة جدارية يقف أمامها طفل ويمدّ
 * يده. والقياس بـvmin لا vh: الشاشة العريضة القصيرة كانت تُصغّرها مرّتين،
 * مرّة بالارتفاع ومرّة بالعرض.
 */
.hud-btn {
  border: 0; cursor: pointer;
  min-width: clamp(68px, 5.5vmin, 96px); height: clamp(68px, 6.4vmin, 92px);
  padding: 0 clamp(14px, 1.4vw, 24px);
  border-radius: 20px;
  background: var(--teal); color: #fff;
  font: inherit; font-size: clamp(17px, 1.7vmin, 24px); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  flex: 0 0 auto;
  transition: transform .12s, filter .12s;
}
.hud-btn:active { transform: scale(.93); filter: brightness(.9); }
.hud-btn.off { background: var(--ink2); }

/*
 * العنوان يتقلّص ولا يدفع.
 * min-width:0 ضروريّ داخل flex: بدونه يرفض العنصر النزول عن عرض نصّه
 * فيدفع الأزرار خارج الشاشة بدل أن يُقصّ هو.
 */
.hud-title { flex: 1 1 auto; min-width: 0; line-height: 1.25; }
.hud-title b {
  display: block; font-size: clamp(20px, 2.4vmin, 36px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-title span {
  display: block; font-size: clamp(12px, 1.2vmin, 18px); color: var(--ink2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hud-score {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--sun); color: #6B4A00;
  padding: 0 clamp(18px, 1.8vw, 28px); height: clamp(68px, 6.4vmin, 92px);
  border-radius: 20px;
  font-size: clamp(22px, 2.4vmin, 36px); font-weight: 800;
  flex: 0 0 auto;
}
.hud-score .star { font-size: 1.1em; }

/* ── المسرح ────────────────────────────────────────── */

/*
 * المسرح يقيس نفسه بالمتبقّي لا بطرحٍ مقدَّر.
 *
 * كان ارتفاعه يطرح رقماً تقريبياً لارتفاع الشريط، فإن اختلف الشريط قليلاً
 * قُصّ أسفل اللعبة أو بقي فراغ. وflex على body يجعل المتصفّح يحسبه بدقّة.
 */
.stage {
  position: relative; z-index: 2;
  flex: 1 1 auto; min-height: 0;
  padding: clamp(12px, 2vh, 30px) clamp(14px, 2.4vw, 44px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 2vh, 26px);
  overflow: hidden;
}

.prompt {
  font-size: clamp(22px, 2.8vw, 44px); font-weight: 800; text-align: center;
  color: var(--teal-d);
}
.prompt small { display: block; font-size: .55em; font-weight: 600; color: var(--ink2); margin-top: 6px; }

/* ── البلاطات ──────────────────────────────────────── */

.grid { display: grid; gap: clamp(10px, 1.6vw, 26px); width: 100%; justify-content: center; }

.tile {
  border: 0; cursor: pointer; font: inherit;
  background: #fff;
  border-radius: var(--r);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .07), 0 14px 30px rgba(23, 37, 35, .10);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  padding: clamp(8px, 1.4vh, 20px);
  min-height: clamp(96px, 15vh, 190px);
  transition: transform .14s, box-shadow .14s;
}
.tile:active { transform: translateY(5px); box-shadow: 0 3px 0 rgba(0, 0, 0, .07); }
.tile .big-emoji { font-size: clamp(38px, 6vw, 92px); line-height: 1; }
.tile .label { font-size: clamp(15px, 1.6vw, 26px); font-weight: 700; }
.tile.right { background: #DDF6EC; box-shadow: 0 0 0 6px var(--mint) inset; }
.tile.wrong { background: #FDE6EA; box-shadow: 0 0 0 6px var(--rose) inset; }
.tile.gone { opacity: 0; pointer-events: none; transform: scale(.6); }

.big {
  border: 0; cursor: pointer; font: inherit; font-weight: 800;
  font-size: clamp(17px, 1.8vw, 27px);
  padding: clamp(14px, 1.6vh, 22px) clamp(22px, 2.4vw, 40px);
  border-radius: 20px; background: var(--teal); color: #fff;
  box-shadow: 0 6px 0 var(--teal-d);
  transition: transform .12s;
}
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--teal-d); }
.big.ghost { background: #fff; color: var(--teal); box-shadow: 0 6px 0 var(--line); }

/* ── حركات ────────────────────────────────────────── */

@keyframes shakeK {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-11px); }
  40%, 60% { transform: translateX(11px); }
}
.shake { animation: shakeK .5s; }

@keyframes popK { 50% { transform: scale(1.22); } }
.pop { animation: popK .32s ease-out; }

@keyframes floatK { to { transform: translateY(-14px); } }
.float { animation: floatK 1.8s ease-in-out infinite alternate; }

.flystar {
  position: fixed; z-index: 60; font-size: 42px; pointer-events: none;
  transition: transform .7s cubic-bezier(.4, 0, .2, 1), opacity .7s;
}

.confetti { position: fixed; inset: 0; z-index: 70; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -6vh; width: 14px; height: 22px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(112vh) rotate(760deg); } }

/* ── شاشة الفوز ───────────────────────────────────── */

.winveil {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(12, 26, 24, .55); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeK .28s;
}
@keyframes fadeK { from { opacity: 0; } }

.wincard {
  background: #fff; border-radius: 34px; text-align: center;
  padding: clamp(24px, 4vh, 52px) clamp(30px, 5vw, 76px);
  animation: riseK .4s cubic-bezier(.2, 1.3, .5, 1);
  max-width: 90vw; max-height: 92vh; overflow-y: auto;
}
@keyframes riseK { from { transform: translateY(40px) scale(.9); opacity: 0; } }
.winemoji { font-size: clamp(56px, 9vw, 120px); animation: popK .6s .15s both; }
.wincard h2 { margin: 6px 0 4px; font-size: clamp(26px, 3.4vw, 52px); color: var(--teal); }
.wincard p { margin: 0 0 14px; color: var(--ink2); font-size: clamp(15px, 1.6vw, 24px); }
.winscore {
  display: inline-block; background: var(--sun); color: #6B4A00;
  padding: 10px 26px; border-radius: 16px; font-size: clamp(22px, 2.4vw, 38px); font-weight: 800;
  margin-bottom: 20px;
}
.winrow { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ── الشاشة الرئيسية ──────────────────────────────── */

.hero { text-align: center; padding: clamp(16px, 3vh, 40px) 20px clamp(8px, 1.5vh, 20px); position: relative; z-index: 2; }
.hero h1 { margin: 0; font-size: clamp(28px, 4vw, 62px); color: var(--teal); }
.hero p { margin: 8px 0 0; color: var(--ink2); font-size: clamp(14px, 1.5vw, 24px); }

.menu {
  position: relative; z-index: 2;
  display: grid; gap: clamp(12px, 1.6vw, 26px);
  grid-template-columns: repeat(auto-fill, minmax(clamp(160px, 17vw, 250px), 1fr));
  padding: clamp(12px, 2vh, 26px) clamp(16px, 3vw, 56px) clamp(30px, 5vh, 60px);
  overflow-y: auto;
  flex: 1 1 auto; min-height: 0;
  align-content: start;
}

.card {
  border: 0; cursor: pointer; font: inherit; color: #fff; text-decoration: none;
  border-radius: 30px; padding: clamp(14px, 2vh, 26px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: clamp(140px, 20vh, 230px);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .12), 0 18px 34px rgba(23, 37, 35, .16);
  transition: transform .16s, box-shadow .16s;
}
.card:active { transform: translateY(7px); box-shadow: 0 3px 0 rgba(0, 0, 0, .12); }
.card .ico { font-size: clamp(42px, 5.5vw, 84px); line-height: 1; }
.card .nm { font-size: clamp(16px, 1.7vw, 27px); font-weight: 800; }
.card .ds { font-size: clamp(11px, 1.1vw, 16px); opacity: .9; font-weight: 600; }

/* ── لوحة الرسم والأدوات ──────────────────────────── */

canvas { border-radius: var(--r); background: #fff; touch-action: none; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.swatch {
  width: clamp(46px, 4.4vw, 68px); height: clamp(46px, 4.4vw, 68px);
  border-radius: 50%; border: 4px solid #fff; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
  transition: transform .12s;
}
.swatch.on { transform: scale(1.22); border-color: var(--ink); }

@media (max-width: 700px) {
  .hud-title span { display: none; }
}

/* ══ تحسينات العرض والحركة ══════════════════════════════ */

/* ── مؤشّر الكلام ────────────────────────────────────────
 *
 * الطفل لا يعرف أن الشاشة تتكلّم إليه ما لم يرَ شيئاً يتحرّك مع الصوت.
 * والنبضة على العنوان تربط الصوت بمصدره — فينتبه بدل أن يستمرّ في اللمس.
 */
body.speaking .prompt { animation: talkK .55s ease-in-out infinite alternate; }
@keyframes talkK { to { transform: scale(1.045); } }

body.speaking .hud-title b::after {
  content: '🔊'; margin-inline-start: 10px; display: inline-block;
  animation: talkK .4s ease-in-out infinite alternate;
}

/* ── ومضات ─────────────────────────────────────────── */
.spark {
  position: fixed; z-index: 65; width: 12px; height: 12px; border-radius: 50%;
  pointer-events: none; animation: sparkK .7s ease-out forwards;
}
@keyframes sparkK {
  from { transform: translate(0,0) scale(1); opacity: 1; }
  to   { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* ── دخول نطّاط ────────────────────────────────────── */
@keyframes bounceInK {
  from { transform: scale(.55) translateY(26px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

/* ── موجة ضوء ─────────────────────────────────────── */
.glow { position: relative; overflow: hidden; }
.glow::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.85) 50%, transparent 70%);
  transform: translateX(-130%);
  animation: glowK .85s ease-out;
  pointer-events: none;
}
@keyframes glowK { to { transform: translateX(130%); } }

/* ── بلاطات أعمق ───────────────────────────────────
 *
 * حافة داخلية فاتحة وأخرى داكنة أسفلها تعطي إحساس الزرّ المجسّم — وهو ما
 * يجعل الطفل يعرف أنه يُضغط قبل أن يجرّب.
 */
.tile {
  background: linear-gradient(180deg,#fff,#FBF8F3);
  border: 2px solid rgba(255,255,255,.9);
}
.tile:hover { transform: translateY(-3px); }
.tile.right { animation: popK .4s; }

/* ── العنوان يتنفّس ────────────────────────────────
 *
 * حركة صغيرة جداً وبطيئة: الشاشة الساكنة تماماً تبدو معطّلة لطفل ينتظر،
 * والحركة الكبيرة تشتّته عن السؤال نفسه.
 */
.prompt { animation: breatheK 3.4s ease-in-out infinite alternate; }
@keyframes breatheK { to { transform: scale(1.012); } }

/* ── بطاقات القائمة ───────────────────────────────── */
.card { position: relative; overflow: hidden; }
.card::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 18%, rgba(255,255,255,.35), transparent 62%);
  pointer-events: none;
}
.card .ico { animation: floatK 2.6s ease-in-out infinite alternate; }
.card:nth-child(2n) .ico { animation-duration: 3.1s; }
.card:nth-child(3n) .ico { animation-duration: 2.2s; }

/* ── تقليل الحركة ──────────────────────────────────
 *
 * بعض الأطفال يُصابون بالدوار، والنظام يعرف ذلك من إعداداته. الحركة
 * الزخرفية تتوقّف ويبقى كل ما يوصل معنى — الومضة والاهتزاز والقصاصات.
 */
@media (prefers-reduced-motion: reduce) {
  body::before, body::after,
  .prompt, .card .ico, body.speaking .prompt, body.speaking .hud-title b::after {
    animation: none !important;
  }
}

/* ── لوحة الصوت ───────────────────────────────────────── */

/*
 * البطاقة تُمرَّر داخلها ولا تتجاوز الشاشة.
 *
 * بلا سقف كانت تطول بطول القائمة — وعلى شاشة قصيرة تخرج أطرافها، أو يضغط
 * الانضغاطُ الصفوفَ تحت مقاسها الأدنى فتصير أصغر من إصبع.
 */
.vcard {
  width: min(680px, 92vw);
  max-height: min(88vh, 780px);
  overflow-y: auto;
  text-align: start;
}
.vcard h2 { text-align: center; }
.vcard > p { text-align: center; }

.vlist { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

.vrow {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border: 2px solid var(--line); background: #fff; cursor: pointer;
  border-radius: 18px; padding: clamp(14px, 1.6vh, 20px) clamp(16px, 1.6vw, 22px);
  font: inherit; font-size: clamp(15px, 1.6vmin, 21px); font-weight: 700;
  min-height: 68px; flex: 0 0 auto;
  text-align: start; transition: transform .12s, border-color .12s;
}
.vrow:active { transform: scale(.985); }
.vrow.on { border-color: var(--teal); background: #EAF6F3; }
.vname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtag {
  flex: 0 0 auto; font-size: .82em; font-weight: 800;
  background: #EFEDE8; color: var(--ink2); padding: 5px 12px; border-radius: 999px;
}
.vtag.good { background: #DDF6EC; color: #12735C; }

.vnone {
  text-align: center; color: var(--ink2); line-height: 1.8;
  font-size: clamp(15px, 1.6vmin, 21px); padding: 18px;
}

/*
 * إرشاد التنصيب — نصّ مرجعيّ لا زخرفة، فحجمه أصغر وسطوره أوسع.
 * تقرؤه المعلّمة مرّة ثم لا تعود إليه.
 */
.vguide {
  background: #FFF8EC; border: 2px solid #F6E3BE; border-radius: 20px;
  padding: clamp(14px, 1.8vh, 22px) clamp(16px, 1.8vw, 24px); margin-bottom: 18px;
}
.vguide b { display: block; font-size: clamp(16px, 1.7vmin, 22px); margin-bottom: 8px; color: #8A6100; }
.vguide p { margin: 0 0 10px; color: var(--ink2); font-size: clamp(14px, 1.4vmin, 19px); line-height: 1.7; }
.vguide ol { margin: 0 0 8px; padding-inline-start: 22px; color: var(--ink); }
.vguide li { font-size: clamp(14px, 1.4vmin, 19px); line-height: 2; }
.vsmall { font-size: clamp(12px, 1.2vmin, 16px) !important; color: var(--ink3, #93A09E) !important; margin: 0 !important; }

/* تنبيه الصوت — أسفل الشاشة، لا يحجب شيئاً ويُغلق بلمسة */
.voicehint {
  position: fixed; z-index: 75; inset-inline: 0; bottom: clamp(14px, 2.4vh, 30px);
  margin-inline: auto; width: max-content; max-width: 92vw;
  border: 0; cursor: pointer; font: inherit;
  background: #8A6100; color: #fff;
  padding: clamp(13px, 1.6vh, 19px) clamp(20px, 2.2vw, 32px);
  border-radius: 18px; font-size: clamp(14px, 1.5vmin, 21px); font-weight: 700;
  box-shadow: 0 12px 34px rgba(0,0,0,.28);
  animation: riseK .5s both;
}
.voicehint b { font-weight: 900; }
