/* بطل الضرب — Layout: one column (max 560px). Sticky top bar (back · title · stars · sound · language);
   below it one view at a time: home (mascot + 4 mode cards + tables progress), table picker, learn grid,
   quiz (question + 4 big answers), race (timer + keypad), memory cards (4×3). Bottom sheet for parents. */
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-arabic-400-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-arabic-700-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #FFF6E8; --surface: #FFFFFF; --ink: #2B2440; --muted: #6E6787; --line: #EADFCB;
  --brand: #FF7A30; --brand-ink: #FFFFFF; --brand-soft: #FFE3CF;
  --ok: #22A55B; --ok-soft: #DDF5E6; --bad: #E5484D; --bad-soft: #FDE2E2; --star: #FFB800;
  --shadow: 0 3px 0 rgba(43,36,64,.12);
  --f: "Readex Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  /* لون مختلف لكل جدول */
  --t1: #8E7CF0; --t2: #2FA8E0; --t3: #22A55B; --t4: #F2A100; --t5: #FF7A30;
  --t6: #E5484D; --t7: #D04FB3; --t8: #4C6EF5; --t9: #12A59B; --t10: #8A6A4F;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1730; --surface: #262042; --ink: #F4F1FF; --muted: #B4ADD0; --line: #3A3360;
    --brand-soft: #4A2E22; --ok-soft: #173D2A; --bad-soft: #4A2228; --shadow: 0 3px 0 rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1B1730; --surface: #262042; --ink: #F4F1FF; --muted: #B4ADD0; --line: #3A3360;
  --brand-soft: #4A2E22; --ok-soft: #173D2A; --bad-soft: #4A2228; --shadow: 0 3px 0 rgba(0,0,0,.35); color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 var(--f); overscroll-behavior: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.ltr { direction: ltr; unicode-bidi: isolate; }

.app { max-width: 560px; margin-inline: auto; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr);
  padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }

/* ---------- الشريط العلوي ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px; }
.top .title { flex: 1; min-width: 0; font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; flex: none; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .flip svg { transform: scaleX(-1); }
.pill { height: 44px; border: 0; border-radius: 14px; padding: 0 12px; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; font-size: .85rem; display: inline-flex; align-items: center; gap: 6px; }
.star-count { color: var(--ink); }
.star-count svg, .star svg { width: 20px; height: 20px; fill: var(--star); stroke: none; }

.view { min-width: 0; display: grid; gap: 16px; align-content: start; padding-top: 6px; animation: in .25s ease; }

/* ---------- الرئيسية ---------- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; background: var(--brand-soft); border-radius: 24px; padding: 14px 16px; }
.hero h1 { margin: 0; font-size: 1.6rem; line-height: 1.2; }
.hero p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.mascot { width: 84px; height: 84px; animation: bob 3s ease-in-out infinite; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { border: 0; border-radius: 22px; padding: 16px 14px; text-align: start; color: #fff; display: grid; gap: 6px; min-height: 132px; align-content: space-between; box-shadow: 0 5px 0 rgba(0,0,0,.18); }
.mode:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.mode .ic { width: 44px; height: 44px; border-radius: 14px; background: rgba(255,255,255,.22); display: grid; place-items: center; font-size: 1.4rem; font-weight: 700; }
.mode b { font-size: 1.12rem; line-height: 1.2; }
.mode span { font-size: .8rem; opacity: .92; line-height: 1.35; }
.m-learn { background: #2FA8E0; } .m-quiz { background: #22A55B; } .m-race { background: #FF7A30; } .m-pairs { background: #8E7CF0; }

.section-title { margin: 4px 0 -4px; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: center; }
.tables { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tcell { border: 0; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); padding: 8px 2px 6px; display: grid; gap: 2px; justify-items: center; }
.tcell b { font-size: 1.35rem; color: var(--tc); line-height: 1.1; }
.tcell .st { display: flex; gap: 1px; direction: ltr; }
.tcell .st svg { width: 12px; height: 12px; fill: var(--line); }
.tcell .st svg.on { fill: var(--star); }
.link-row { display: flex; justify-content: center; gap: 18px; }
.link { border: 0; background: none; color: var(--muted); font-size: .85rem; text-decoration: underline; padding: 6px; }

/* ---------- اختيار الجدول ---------- */
.picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.pick { aspect-ratio: 1; border: 3px solid transparent; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); font-size: 1.7rem; font-weight: 700; color: var(--tc); display: grid; place-items: center; }
.pick[aria-pressed="true"] { background: var(--tc); color: #fff; border-color: rgba(0,0,0,.08); }
.wide-btn { min-height: 56px; border: 0; border-radius: 18px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 1.1rem; box-shadow: 0 4px 0 rgba(0,0,0,.18); padding: 0 18px; }
.wide-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.wide-btn:disabled { opacity: .45; }
.wide-btn.soft { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.hint { text-align: center; color: var(--muted); font-size: .9rem; margin: 0; }

/* ---------- التعلّم ---------- */
.learn-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { background: var(--tc); color: #fff; border-radius: 14px; padding: 6px 14px; font-weight: 700; font-size: 1.15rem; }
.facts { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(5, auto); grid-auto-flow: column; gap: 8px; }
.fact { border: 0; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; font-size: 1.25rem; font-weight: 700; direction: ltr; }
.fact .r { min-width: 44px; text-align: center; border-radius: 10px; background: var(--bg); color: transparent; transition: .2s; }
.fact.on .r { color: var(--tc); background: transparent; }
.fact[aria-current="true"] { outline: 3px solid var(--tc); }
.dots { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; justify-items: center; }
.dots .grid { display: grid; gap: 6px; direction: ltr; }
.dots .row { display: flex; gap: 5px; padding: 4px 6px; border-radius: 10px; background: var(--bg); }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--tc); display: block; }
.dots p { margin: 0; color: var(--muted); font-size: .9rem; text-align: center; }
.dots .eq { font-size: 1.4rem; font-weight: 700; color: var(--ink); direction: ltr; }

/* ---------- التمرين ---------- */
.progress { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: inherit; transition: width .3s; }
.qmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; }
.qcard { background: var(--surface); border-radius: 26px; box-shadow: var(--shadow); padding: 28px 12px; text-align: center; font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 700; direction: ltr; line-height: 1.1; }
.qcard .q { color: var(--brand); }
.qcard.shake { animation: shake .4s; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ans { min-height: 78px; border: 0; border-radius: 20px; background: var(--surface); box-shadow: 0 4px 0 var(--line); font-size: 2rem; font-weight: 700; direction: ltr; }
.ans:active { transform: translateY(2px); }
.ans.good { background: var(--ok); color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.2); animation: pop .3s; }
.ans.badc { background: var(--bad); color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.ans:disabled { cursor: default; }
.feedback { min-height: 28px; text-align: center; font-weight: 700; margin: 0; }
.feedback.good { color: var(--ok); } .feedback.badc { color: var(--bad); }

/* ---------- النتيجة ---------- */
.result { background: var(--surface); border-radius: 26px; box-shadow: var(--shadow); padding: 24px 16px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.result h2 { margin: 0; font-size: 1.5rem; }
.result .big { font-size: 2.6rem; font-weight: 700; color: var(--brand); line-height: 1.1; }
.bigstars { display: flex; gap: 8px; direction: ltr; }
.bigstars svg { width: 54px; height: 54px; fill: var(--line); }
.bigstars svg.on { fill: var(--star); animation: starpop .5s both; }
.bigstars svg.on:nth-child(2) { animation-delay: .2s; } .bigstars svg.on:nth-child(3) { animation-delay: .4s; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.mistakes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.mistakes span { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 4px 10px; font-weight: 700; direction: ltr; }

/* ---------- سباق الوقت ---------- */
.race-top { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.race-top div { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 6px; }
.race-top b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.race-top span { font-size: .75rem; color: var(--muted); }
.timebar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.timebar i { display: block; height: 100%; background: var(--brand); transition: width 1s linear; }
.typed { display: inline-block; min-width: 1.8em; border-bottom: 4px solid var(--brand); color: var(--ink); }
.qcard.good .typed { color: var(--ok); border-color: var(--ok); }
.qcard.badc .typed { color: var(--bad); border-color: var(--bad); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; direction: ltr; }
.key { min-height: 60px; border: 0; border-radius: 18px; background: var(--surface); box-shadow: 0 4px 0 var(--line); font-size: 1.7rem; font-weight: 700; }
.key:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.key svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.key.go { background: var(--ok); color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.2); }

/* ---------- لعبة الذاكرة ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; perspective: 800px; }
.card { aspect-ratio: 4 / 3.4; border: 0; padding: 0; background: none; position: relative; transform-style: preserve-3d; transition: transform .35s; }
.card.open, .card.done { transform: rotateY(180deg); }
.card .face { position: absolute; inset: 0; border-radius: 18px; display: grid; place-items: center; backface-visibility: hidden; box-shadow: var(--shadow); font-weight: 700; direction: ltr; }
.card .back { background: #8E7CF0; color: rgba(255,255,255,.85); font-size: 2rem; }
.card .front { background: var(--surface); transform: rotateY(180deg); font-size: clamp(1.3rem, 6.5vw, 1.9rem); }
.card .front.r { color: #8E7CF0; font-size: clamp(1.7rem, 8vw, 2.3rem); }
.card.done .front { background: var(--ok-soft); color: var(--ok); }

/* ---------- النافذة والتنبيه ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(20,16,36,.55); display: grid; align-items: end; justify-items: center; }
.sheet { width: min(560px, 100%); max-height: 88dvh; overflow: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; animation: up .22s ease; user-select: text; }
.sheet:focus { outline: none; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet input { font: inherit; font-size: 1.3rem; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; text-align: center; direction: ltr; }
.sheet p { margin: 0; }
.hard { display: flex; flex-wrap: wrap; gap: 8px; }
.hard span { background: var(--bad-soft); color: var(--bad); border-radius: 12px; padding: 6px 12px; font-weight: 700; direction: ltr; }
.tip { background: var(--brand-soft); border-radius: 16px; padding: 12px 14px; font-size: .9rem; }
.toast { position: fixed; top: calc(70px + env(safe-area-inset-top, 0px)); inset-inline: 0; margin-inline: auto; width: max-content; max-width: 90%; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 700; z-index: 40; text-align: center; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 35; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }

@keyframes in { from { opacity: 0; transform: translateY(8px); } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes pop { 50% { transform: scale(1.06); } }
@keyframes starpop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-3deg); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 360px) { .mode { min-height: 118px; padding: 12px; } .mode b { font-size: 1rem; } .tcell b { font-size: 1.15rem; } }

@media (max-width: 420px) { .top .title { font-size: 1rem; } .pill { padding: 0 9px; } }
