/* Motion, new components and phone polish. Loaded after style.css. */

* { -webkit-tap-highlight-color: transparent; }
button, a, input { touch-action: manipulation; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Living background ---------- */
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.5; animation: drift 26s ease-in-out infinite alternate; }
.blob.b1 { width: 60vmax; height: 60vmax; left: -15vmax; top: -20vmax; background: #a569ff; }
.blob.b2 { width: 50vmax; height: 50vmax; right: -18vmax; top: 25vh; background: #ff4f8b; opacity: 0.32; animation-duration: 32s; animation-delay: -8s; }
.blob.b3 { width: 55vmax; height: 55vmax; left: 10vw; bottom: -30vmax; background: #14b8ff; opacity: 0.3; animation-duration: 38s; animation-delay: -15s; }
@keyframes drift { from { transform: translate(0, 0) scale(1); } to { transform: translate(8vw, 7vh) scale(1.18); } }
.shoot { position: absolute; width: 150px; height: 2px; background: linear-gradient(90deg, #fff, transparent); opacity: 0; animation: shoot 11s linear infinite; }
.shoot.s1 { top: 14%; left: 78%; }
.shoot.s2 { top: 38%; left: 94%; animation-delay: 4.5s; animation-duration: 14s; }
.shoot.s3 { top: 6%; left: 46%; animation-delay: 8s; animation-duration: 13s; }
@keyframes shoot {
  0% { opacity: 0; transform: translate(0, 0) rotate(-25deg); }
  2% { opacity: 1; }
  9% { opacity: 0; transform: translate(-460px, 215px) rotate(-25deg); }
  100% { opacity: 0; }
}

/* ---------- Page entrance: blocks rise in one after the other ---------- */
.view.enter > * { animation: rise 0.65s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(26px) scale(0.98); } to { opacity: 1; transform: none; } }
.letter { animation: letterIn 0.8s cubic-bezier(0.2, 1.4, 0.4, 1) both; animation-delay: calc(var(--k, 0) * 70ms + 200ms); }
@keyframes letterIn { from { opacity: 0; transform: translateY(0.5em) scale(0.5) rotate(-14deg); } to { opacity: 1; transform: none; } }

/* ---------- Buttons: shine sweep ---------- */
.btn { position: relative; overflow: hidden; min-height: 46px; }
.btn::after { content: ""; position: absolute; top: 0; left: -70%; width: 45%; height: 100%; background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.55), transparent); transform: skewX(-20deg); transition: left 0.6s; pointer-events: none; }
@media (hover: hover) { .btn:hover::after { left: 140%; } }
.chip-btn { min-height: 40px; }
.install { margin-top: 6px; }

/* ---------- Planets: orbiting moons and tilt ---------- */
.orb { --tx: 0px; --ty: 0px; --rad: 104px; transform: translate(var(--tx), var(--ty)); }
.orb.moon::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle at 35% 30%, #fff, #d8d1ff 60%, #8a7fd0); box-shadow: 0 0 14px rgba(255, 255, 255, 0.7);
  animation: orbit 9s linear infinite;
}
.planet:nth-child(2) .orb::before { animation-duration: 12s; animation-direction: reverse; }
.planet:nth-child(3) .orb::before { animation-duration: 7s; }
.planet:nth-child(4) .orb::before { animation-duration: 10s; animation-direction: reverse; }
@keyframes orbit {
  from { transform: rotate(0deg) translateX(var(--rad)) rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) translateX(var(--rad)) rotate(-180deg) scale(0.75); }
  to { transform: rotate(360deg) translateX(var(--rad)) rotate(-360deg) scale(1); }
}
.planet:hover .orb, .planet:focus-visible .orb { transform: translate(var(--tx), var(--ty)) scale(1.1) rotate(-4deg); }
.planet:active .orb { transform: scale(0.95); }

/* ---------- Mascot eyes and blinking ---------- */
.mascot .pupil { transform: translate(var(--px, 0px), var(--py, 0px)); transition: transform 0.08s linear; }
.hero-mascot .mascot .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } }

/* ---------- Floating XP, confetti, level-up screen ---------- */
.flyxp { position: absolute; transform: translateX(-50%); font-family: var(--display); font-size: 1.5rem; color: var(--lime); -webkit-text-stroke: 0.1em var(--ink); paint-order: stroke fill; animation: flyup 1.05s ease-out forwards; z-index: 80; }
@keyframes flyup { from { opacity: 1; } to { opacity: 0; transform: translate(-50%, -56px); } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 95; }
.levelup { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(30, 12, 5, 0.88); backdrop-filter: blur(8px); animation: fadein 0.3s; overflow: hidden; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.levelup .rays { position: absolute; width: 150vmax; height: 150vmax; background: repeating-conic-gradient(rgba(255, 207, 51, 0.2) 0 9deg, transparent 9deg 18deg); -webkit-mask: radial-gradient(circle, #000 0, transparent 55%); mask: radial-gradient(circle, #000 0, transparent 55%); animation: spin 24s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lu-card { position: relative; text-align: center; animation: luin 0.7s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes luin { from { transform: scale(0.3) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
.lu-top { font-family: var(--display); font-size: clamp(2.6rem, 11vw, 4.6rem); line-height: 1; margin: 0; color: var(--sun); -webkit-text-stroke: 0.08em var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--sun-d); }
.lu-badge { width: 150px; height: 150px; margin: 40px auto 36px; display: grid; place-items: center; background: linear-gradient(160deg, var(--lime), #5fd01c); border: 7px solid var(--ink); border-radius: 38px; transform: rotate(45deg); box-shadow: 0 10px 0 var(--lime-d), 0 0 60px rgba(184, 255, 61, 0.6); animation: badgepulse 1.6s ease-in-out infinite alternate; }
.lu-badge b { transform: rotate(-45deg); font-family: var(--display); font-weight: 400; font-size: 5rem; color: var(--ink); }
@keyframes badgepulse { to { box-shadow: 0 10px 0 var(--lime-d), 0 0 100px rgba(184, 255, 61, 0.9); } }
.lu-rank { font-family: var(--display); font-size: 2rem; margin: 0 0 16px; }

/* ---------- Home: word of the day ---------- */
.wotdcard { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.wotdcard h2 { color: var(--sky); }
.wotd { display: flex; align-items: center; gap: 12px; }
.wd-emo { font-size: 2.4rem; }
.wd-ar { background: none; border: 0; color: #fff; font-size: 3rem; line-height: 1.2; padding: 0; cursor: pointer; }
.wd-info b { display: block; font-family: var(--display); font-weight: 400; font-size: 1.3rem; }
.wd-info small { opacity: 0.75; font-weight: 800; }
.wotdcard .btn { padding: 8px 18px 10px; }

/* ---------- Column method ---------- */
.numfield { display: grid; gap: 2px; font-weight: 800; font-size: 0.95rem; }
.numfield input, .searchbox input {
  font-family: var(--display); font-size: 1.6rem; width: 7.5ch; color: var(--ink); background: #fffbe8;
  border: 0; border-radius: 14px; padding: 4px 12px; box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.12);
}
.col-stage { background: var(--white); color: var(--ink); border-radius: 22px; padding: 14px 16px 16px; display: grid; justify-content: center; margin: 6px 0 14px; overflow-x: auto; }
.crow { display: flex; justify-content: flex-end; }
.cc { width: 1.12em; text-align: center; font-family: var(--display); font-size: 2.7rem; line-height: 1.12; border-radius: 10px; }
.cc.mark { font-size: 1.15rem; color: var(--pink-d); align-self: flex-end; animation: popin 0.4s cubic-bezier(0.2, 1.8, 0.4, 1); }
.cc.ten { color: var(--sky-d); }
.cc.sym { color: var(--pink-d); }
.cc.cur { background: rgba(255, 207, 51, 0.5); }
.cc.res { color: #0f8f66; animation: popin 0.45s cubic-bezier(0.2, 1.8, 0.4, 1); }
@keyframes popin { from { transform: scale(0); opacity: 0; } to { transform: none; opacity: 1; } }
.cline { height: 6px; background: var(--ink); border-radius: 3px; margin: 4px 0; }
.col-steps { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.col-steps li { border-left: 6px solid var(--a); background: rgba(255, 255, 255, 0.08); border-radius: 0 12px 12px 0; padding: 4px 12px; animation: rise 0.4s both; }
.col-steps li.now { background: rgba(255, 207, 51, 0.22); }
.col-steps li.final { border-color: var(--lime); font-family: var(--display); font-size: 1.4rem; }
.col-steps li.final b { color: var(--lime); }

/* ---------- Brain boosters and more tests ---------- */
.boosters { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.test-card.c4 { --c: var(--sky); --cd: var(--sky-d); }
.test-card.c5 { --c: var(--violet); --cd: var(--violet-d); }
.q-prompt.long { font-size: clamp(1.9rem, 8.5vw, 3.3rem); }
.q-prompt.wp { font-family: var(--body); font-weight: 800; font-size: clamp(1.2rem, 4.2vw, 1.75rem); line-height: 1.4; text-align: left; justify-content: flex-start; }
.cmp { display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; border: 4px dashed #e3c9a3; border-radius: 12px; color: #e3c9a3; vertical-align: middle; }

/* ---------- Arabic: topics, list ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; }
.cat { display: grid; justify-items: center; align-content: start; gap: 3px; padding: 12px 8px 12px; border-radius: 20px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.08); color: var(--white); cursor: pointer; font-family: var(--body); transition: transform 0.12s; }
.cat:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.15); }
.cat.on { background: var(--a); color: var(--ink); border-color: transparent; box-shadow: 0 5px 0 var(--ad); }
.cat-i { font-size: 2rem; line-height: 1.1; }
.cat b { font-size: 0.95rem; line-height: 1.15; text-align: center; }
.cat small { font-weight: 800; opacity: 0.8; }
.cat-bar { width: 80%; height: 6px; border-radius: 9px; background: rgba(0, 0, 0, 0.25); overflow: hidden; }
.cat-bar u { display: block; height: 100%; background: var(--lime); border-radius: 9px; transition: width 0.5s; }
.searchbox { display: block; margin: 4px 0 8px; }
.searchbox input { width: 100%; font-family: var(--body); font-weight: 800; font-size: 1.1rem; }
.wlist { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; max-height: 520px; overflow: auto; padding-right: 4px; }
.wrow { display: grid; grid-template-columns: 2.2rem 1fr 1fr 1.2fr 2rem; align-items: center; gap: 8px; width: 100%; text-align: left; background: rgba(255, 255, 255, 0.08); border: 2px solid var(--line); border-radius: 14px; padding: 2px 12px; color: var(--white); cursor: pointer; font: inherit; min-height: 52px; }
.wrow:hover { background: rgba(255, 255, 255, 0.16); }
.w-ar { font-size: 1.7rem; line-height: 1.35; justify-self: start; }
.w-tr { opacity: 0.7; font-size: 0.95rem; }
.w-en { font-weight: 800; }
.flash-ctrl .btn { min-width: 52px; }

/* ---------- Memory Match ---------- */
.mm-bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; margin: 14px 0; font-weight: 800; }
.mm-bar b { font-family: var(--display); font-weight: 400; font-size: 1.4rem; }
.mm-bar .btn { margin-left: auto; padding: 6px 20px 8px; }
.mm-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 560px; }
.mm-hint { grid-column: 1 / -1; }
.mcard { aspect-ratio: 3 / 4; perspective: 700px; border: 0; background: none; padding: 0; cursor: pointer; }
.mc-in { position: relative; display: block; width: 100%; height: 100%; transition: transform 0.5s cubic-bezier(0.3, 1.3, 0.5, 1); transform-style: preserve-3d; }
.mcard.flipped .mc-in, .mcard.matched .mc-in { transform: rotateY(180deg); }
.mc-front, .mc-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-content: center; justify-items: center; gap: 2px; border-radius: 16px; }
.mc-front { background: linear-gradient(160deg, var(--violet), var(--violet-d)); color: #fff; font-family: var(--display); font-size: 2.4rem; box-shadow: 0 5px 0 #6a35c4; }
.mc-back { background: #fff; color: var(--ink); transform: rotateY(180deg); box-shadow: 0 5px 0 #e3c9a3; text-align: center; padding: 4px; }
.mcard.matched .mc-back { background: var(--lime); box-shadow: 0 5px 0 var(--lime-d); }
.mcard.matched { animation: matchpop 0.5s; }
@keyframes matchpop { 40% { transform: scale(1.1); } }
.mc-ar { font-size: 2rem; line-height: 1.3; }
.mc-emo { font-size: 2rem; line-height: 1.1; }
.mc-en { font-weight: 800; font-size: 0.9rem; line-height: 1.1; }

/* ---------- Phone and tablet polish ---------- */
@media (max-width: 760px) {
  /* a blurred top bar would trap the fixed bottom tabs inside itself */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: #2a1309; }
  body.quizzing { padding-bottom: 24px; }
  body.quizzing .tabs { display: none; }
  .btn { min-height: 48px; }
  .key { padding: 12px 0 14px; font-size: 2rem; }
  .numpad { width: min(100%, 360px); gap: 10px; }
  .num-display { font-size: 2.8rem; }
  .cc { font-size: 2.1rem; }
  .wrow { grid-template-columns: 2rem 1fr 1fr 1.6rem; }
  .w-tr { display: none; }
  .mm-board { grid-template-columns: repeat(3, 1fr); }
  .mm-bar .btn { margin-left: 0; }
  .wotdcard { flex-wrap: wrap; }
  .orb { --rad: 92px; }
  .choices { grid-template-columns: 1fr 1fr; }
  .choice { font-size: 1.3rem; min-height: 70px; }
  .choice .ar { font-size: 2.1rem; }
  .q-prompt { font-size: clamp(2.2rem, 12vw, 3.6rem); }
  .q-prompt.long { font-size: clamp(1.7rem, 8.5vw, 2.6rem); }
  .q-card { padding: 14px 14px 18px; }
  .results h3 { font-size: 1.9rem; }
  .stamp { width: 120px; height: 120px; font-size: 3.6rem; }
}
@media (max-width: 380px) {
  .choices { grid-template-columns: 1fr; }
  .hud { gap: 6px; }
  .iconbtn { width: 34px; height: 34px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { position: static; }
  .tabs { position: static !important; border: 0 !important; background: none !important; }
  body { padding-bottom: 0; }
  .q-mascot { display: none; }
  .numarea { grid-template-columns: 1fr 1fr; align-items: center; }
  .num-display { font-size: 2.4rem; }
  .key { padding: 6px 0 8px; font-size: 1.5rem; }
  .q-prompt { font-size: 2.4rem; }
}
@supports (padding: max(0px)) {
  .topbar { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); padding-top: max(8px, env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .shoot, .view.enter > *, .letter, .orb.moon::before, .hero-mascot .mascot .eye, .flyxp, .levelup, .levelup .rays, .lu-card, .lu-badge,
  .cc.mark, .cc.res, .col-steps li, .mcard.matched { animation: none !important; }
  .mc-in { transition: none; }
  .btn::after { display: none; }
  .confetti, .flyxp { display: none; }
}
