:root {
  --purple-950: #321043;
  --purple-900: #48115f;
  --purple-800: #641b83;
  --purple-700: #7d2ca0;
  --purple-100: #f0e4f5;
  --purple-50: #fbf6fd;
  --green-700: #347e18;
  --green-100: #e8f6e2;
  --blue-700: #1575ad;
  --blue-100: #e5f5ff;
  --yellow-500: #f7b900;
  --yellow-100: #fff6cd;
  --red-100: #fff0ef;
  --ink: #26182d;
  --muted: #6e6473;
  --line: #e7dbea;
  --surface: #fff;
  --font: "Tajawal", Tahoma, Arial, sans-serif;
  --shadow: 0 24px 70px rgba(67, 25, 82, 0.14);
}

*, *::before, *::after { box-sizing: border-box; }

html { min-width: 320px; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 14%, rgba(218, 241, 255, 0.8), transparent 28%),
    radial-gradient(circle at 94% 80%, rgba(243, 218, 255, 0.75), transparent 30%),
    #fbf8fc;
  font-family: var(--font);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; font: inherit; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: 4px solid var(--yellow-500); outline-offset: 4px; }

.skip-link {
  position: fixed;
  z-index: 1000;
  inset: 12px auto auto 50%;
  padding: 10px 18px;
  color: white;
  background: var(--purple-900);
  border-radius: 999px;
  transform: translate(-50%, -180%);
}

.skip-link:focus { transform: translate(-50%, 0); }

.learning-header {
  position: sticky;
  z-index: 20;
  inset-block-start: 0;
  display: grid;
  grid-template-columns: 130px minmax(200px, 520px) 130px;
  gap: 24px;
  align-items: center;
  min-height: 82px;
  padding: 10px clamp(18px, 4vw, 54px);
  background: rgba(255, 255, 255, 0.93);
  border-block-end: 1px solid rgba(100, 27, 131, 0.1);
  backdrop-filter: blur(16px);
}

.learning-brand {
  display: grid;
  width: 112px;
  height: 58px;
  place-items: center;
  overflow: hidden;
}

.learning-brand img { width: 116px; height: auto; margin-block: -28px; }

.exit-link {
  justify-self: end;
  color: var(--purple-800);
  font-weight: 800;
}

.header-progress { text-align: center; }
.header-progress > span { display: block; margin-block-end: 5px; color: var(--muted); font-size: 14px; font-weight: 700; }
.header-progress-track { height: 9px; overflow: hidden; background: #eee7f0; border-radius: 999px; }
.header-progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--purple-800), #a953c6); border-radius: inherit; transition: width 450ms ease; }

.learning-main { width: min(1050px, calc(100% - 34px)); margin-inline: auto; padding-block: clamp(30px, 6vw, 74px); }
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in 340ms ease both; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.welcome-screen {
  grid-template-columns: minmax(300px, 0.9fr) minmax(340px, 1.1fr);
  gap: clamp(34px, 7vw, 88px);
  align-items: center;
  min-height: calc(100vh - 230px);
}

.welcome-screen.is-active { display: grid; }
.welcome-copy h1, .path-heading h1, .finish-screen h1 { margin: 8px 0 14px; font-size: clamp(34px, 5vw, 60px); line-height: 1.2; }
.welcome-copy > p, .path-heading p, .finish-screen > p { max-width: 720px; margin: 0 0 26px; color: var(--muted); font-size: clamp(17px, 2vw, 21px); }
.eyebrow, .activity-kicker { color: var(--purple-700); font-weight: 900; }

.welcome-art {
  position: relative;
  display: grid;
  min-height: 430px;
  place-items: center;
  background: linear-gradient(150deg, #fff 0%, #f7effb 100%);
  border: 1px solid var(--line);
  border-radius: 48% 52% 45% 55% / 55% 44% 56% 45%;
  box-shadow: var(--shadow);
}

.mascot-face {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 45px;
  width: 210px;
  height: 210px;
  padding-block-start: 45px;
  color: white;
  background: linear-gradient(145deg, #8f36b1, #53106f);
  border: 12px solid white;
  border-radius: 50%;
  box-shadow: 0 22px 45px rgba(82, 21, 107, 0.25);
  font-size: 38px;
  text-align: center;
}

.mascot-face strong { position: absolute; inset: 82px 0 auto; font-size: 70px; font-weight: 500; }
.floating-number { position: absolute; display: grid; width: 72px; height: 72px; place-items: center; color: var(--purple-800); background: white; border-radius: 22px; box-shadow: 0 14px 30px rgba(69, 24, 85, 0.13); font-size: 30px; font-weight: 900; transform: rotate(var(--tilt)); }
.number-one { inset: 36px auto auto 34px; --tilt: -9deg; }
.number-two { inset: auto 25px 50px auto; color: var(--green-700); --tilt: 8deg; }
.number-three { inset: 55px 32px auto auto; color: var(--yellow-500); --tilt: 11deg; }

.journey-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-block: 0 28px; }
.journey-preview span { padding: 11px 14px; background: rgba(255,255,255,0.8); border: 1px solid var(--line); border-radius: 16px; font-weight: 700; }
.journey-preview b { display: inline-grid; width: 28px; height: 28px; margin-inline-end: 4px; color: white; background: var(--purple-800); border-radius: 50%; place-items: center; }

.primary-button, .secondary-button {
  display: inline-flex;
  min-height: 54px;
  padding: 13px 25px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 17px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button { color: #fff; background: linear-gradient(135deg, var(--purple-700), var(--purple-900)); box-shadow: 0 12px 25px rgba(100, 27, 131, 0.23); }
.secondary-button { color: var(--purple-900); background: white; border: 1px solid var(--line); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-2px); }
.primary-button:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }
.local-note { margin: 14px 0 0 !important; font-size: 14px !important; }

.activity-screen { max-width: 900px; margin-inline: auto; }
.activity-topline { display: grid; grid-template-columns: 54px 1fr 54px; gap: 16px; align-items: center; margin-block-end: 16px; }
.activity-topline h1 { margin: 2px 0 0; font-size: clamp(25px, 4vw, 38px); line-height: 1.25; }
.icon-button, .sound-button { display: grid; width: 52px; height: 52px; padding: 0; place-items: center; color: var(--purple-800); background: white; border: 1px solid var(--line); border-radius: 16px; cursor: pointer; box-shadow: 0 8px 20px rgba(65, 23, 80, 0.07); }
.sound-button svg { width: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-button { font-size: 24px; }

.round-progress { display: flex; gap: 18px; align-items: center; margin-block-end: 20px; color: var(--muted); font-size: 14px; font-weight: 800; }
.round-progress > div { flex: 1; height: 8px; overflow: hidden; background: #ebe3ee; border-radius: 999px; }
.round-progress > div span { display: block; width: 33.333%; height: 100%; background: var(--yellow-500); border-radius: inherit; transition: width 350ms ease; }

.activity-card { min-height: 500px; padding: clamp(22px, 5vw, 46px); background: rgba(255,255,255,0.94); border: 1px solid var(--line); border-radius: 32px; box-shadow: var(--shadow); }
.instruction { max-width: 720px; margin: 0 auto 26px; color: var(--ink); font-size: clamp(20px, 3vw, 28px); font-weight: 800; text-align: center; }
.activity-workspace { min-height: 270px; }
.activity-actions { display: flex; gap: 12px; justify-content: center; margin-block-start: 25px; }
.feedback { max-width: 640px; margin: 20px auto 0; padding: 14px 18px; background: var(--green-100); border: 1px solid #cce9c0; border-radius: 15px; color: #276714; font-weight: 800; text-align: center; }
.feedback.try-again { color: #7a3c18; background: var(--yellow-100); border-color: #f1d982; }

.hands-stage { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(14px, 4vw, 34px); max-width: 700px; margin-inline: auto; }
.hand-panel { padding: 20px 14px 16px; background: var(--purple-50); border: 2px solid var(--purple-100); border-radius: 26px; text-align: center; }
.hand-panel > span { color: var(--muted); font-size: 14px; font-weight: 800; }
.finger-row { display: flex; min-height: 170px; margin-block: 14px; align-items: end; justify-content: center; gap: 5px; direction: ltr; }
.finger {
  position: relative;
  width: clamp(34px, 7vw, 50px);
  height: var(--finger-height);
  padding: 0;
  background: #d9d1dc;
  border: 0;
  border-radius: 999px 999px 18px 18px;
  cursor: pointer;
  transition: height 180ms ease, background 180ms ease, transform 180ms ease;
}
.finger::after { position: absolute; inset: auto 22% 12px; height: 8px; content: ""; background: rgba(255,255,255,0.5); border-radius: 999px; }
.finger.raised { height: calc(var(--finger-height) + 35px); background: linear-gradient(#f9c082, #e99b63); box-shadow: 0 10px 20px rgba(169, 92, 43, 0.18); }
.finger:hover { transform: translateY(-3px); }
.finger:nth-child(1), .finger:nth-child(5) { --finger-height: 90px; }
.finger:nth-child(2), .finger:nth-child(4) { --finger-height: 112px; }
.finger:nth-child(3) { --finger-height: 124px; }
.hand-count { display: inline-grid; min-width: 44px; height: 38px; padding-inline: 10px; place-items: center; color: white; background: var(--purple-800); border-radius: 999px; font-size: 22px; font-weight: 900; }
.total-badge { width: fit-content; margin: 20px auto 0; padding: 10px 20px; color: var(--purple-900); background: var(--yellow-100); border-radius: 999px; font-size: 20px; font-weight: 900; }

.dot-groups { display: grid; grid-template-columns: repeat(2, minmax(140px, 240px)); gap: 24px; justify-content: center; align-items: stretch; }
.dot-group { display: flex; min-height: 170px; padding: 26px; flex-wrap: wrap; align-content: center; justify-content: center; gap: 12px; background: var(--blue-100); border: 3px solid transparent; border-radius: 26px; }
.dot-group.mirror { background: var(--purple-50); border-color: var(--purple-100); }
.dot { width: 38px; height: 38px; background: var(--blue-700); border-radius: 50%; box-shadow: inset 0 -5px rgba(0,0,0,0.1); animation: pop-in 260ms ease both; }
.dot-group.mirror .dot { background: var(--purple-700); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.4); } }

.choice-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-block-start: 24px; }
.choice-button { min-width: 92px; min-height: 62px; padding: 10px 20px; color: var(--purple-900); background: #fff; border: 2px solid var(--line); border-radius: 18px; cursor: pointer; font-size: 24px; font-weight: 900; }
.choice-button:hover, .choice-button.selected { color: white; background: var(--purple-800); border-color: var(--purple-800); transform: translateY(-2px); }

.ten-frame { display: grid; grid-template-columns: repeat(5, 64px); gap: 8px; width: fit-content; margin-inline: auto; padding: 12px; direction: ltr; background: var(--ink); border-radius: 18px; }
.ten-cell { display: grid; width: 64px; height: 64px; padding: 0; place-items: center; background: white; border: 0; border-radius: 10px; cursor: pointer; }
.ten-cell::after { width: 42px; height: 42px; content: ""; background: #ece8ee; border-radius: 50%; transition: transform 180ms ease, background 180ms ease; }
.ten-cell.filled::after { background: var(--blue-700); box-shadow: inset 0 -6px rgba(0,0,0,0.12); transform: scale(1.02); }
.ten-cell.added::after { background: var(--yellow-500); }
.ten-equation { margin: 22px 0 0; color: var(--purple-900); font-size: clamp(28px, 6vw, 46px); font-weight: 900; text-align: center; direction: ltr; }

.group-builder { display: grid; gap: 18px; }
.known-fact { width: fit-content; margin-inline: auto; padding: 10px 18px; color: var(--green-700); background: var(--green-100); border-radius: 999px; font-size: 20px; font-weight: 900; direction: ltr; }
.group-grid { display: grid; grid-template-columns: repeat(3, minmax(100px, 1fr)); gap: 12px; max-width: 650px; margin-inline: auto; }
.number-group { display: flex; min-height: 96px; padding: 14px; flex-wrap: wrap; align-content: center; justify-content: center; gap: 8px; background: var(--purple-50); border: 2px solid var(--purple-100); border-radius: 20px; }
.number-group.new { background: var(--yellow-100); border-color: var(--yellow-500); animation: pop-in 280ms ease both; }
.number-group i { width: 25px; height: 25px; background: var(--purple-700); border-radius: 50%; }
.number-group.new i { background: var(--yellow-500); }
.bridge-equation { color: var(--purple-900); font-size: clamp(24px, 5vw, 40px); font-weight: 900; text-align: center; direction: ltr; }

.path-heading { margin-block-end: 30px; text-align: center; }
.path-heading p { margin-inline: auto; }
.path-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.path-card { position: relative; display: grid; grid-template-columns: 70px 1fr auto; gap: 16px; align-items: center; min-height: 145px; padding: 22px; text-align: start; background: white; border: 1px solid var(--line); border-radius: 25px; box-shadow: 0 14px 35px rgba(65, 23, 80, 0.08); }
button.path-card { width: 100%; cursor: pointer; }
.path-card:disabled { opacity: 0.55; cursor: not-allowed; }
.path-number { display: grid; width: 60px; height: 60px; place-items: center; color: white; background: var(--purple-800); border-radius: 19px; font-size: 27px; font-weight: 900; }
.path-card.completed .path-number { background: var(--green-700); }
.path-copy strong { display: block; margin-block-end: 4px; font-size: 21px; }
.path-copy small { display: block; color: var(--muted); font-size: 15px; line-height: 1.6; }
.path-state { color: var(--purple-700); font-weight: 900; }
.path-card.completed .path-state { color: var(--green-700); }
.text-button { display: block; margin: 28px auto 0; padding: 8px; color: var(--muted); background: transparent; border: 0; cursor: pointer; text-decoration: underline; }

.finish-screen { max-width: 780px; margin-inline: auto; padding: clamp(30px, 6vw, 65px); text-align: center; background: white; border: 1px solid var(--line); border-radius: 34px; box-shadow: var(--shadow); }
.finish-screen > p { margin-inline: auto; }
.celebration { display: flex; align-items: center; justify-content: center; gap: 18px; color: var(--yellow-500); font-size: 32px; }
.celebration strong { display: grid; width: 82px; height: 82px; place-items: center; color: white; background: var(--green-700); border-radius: 50%; font-size: 42px; }
.finish-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-block: 28px; }
.finish-summary div { padding: 14px 8px; background: var(--purple-50); border-radius: 16px; }
.finish-summary strong { display: block; color: var(--purple-800); font-size: 24px; }
.finish-summary span { color: var(--muted); font-size: 13px; font-weight: 700; }
.finish-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

@media (max-width: 760px) {
  .learning-header { grid-template-columns: 92px 1fr 60px; gap: 10px; min-height: 72px; padding-inline: 14px; }
  .learning-brand { width: 90px; }
  .learning-brand img { width: 96px; margin-block: -24px; }
  .exit-link { font-size: 14px; }
  .header-progress > span { font-size: 12px; }
  .learning-main { width: min(100% - 22px, 1050px); padding-block: 24px 40px; }
  .welcome-screen.is-active { display: flex; min-height: auto; flex-direction: column; }
  .welcome-art { width: min(100%, 440px); min-height: 310px; order: 2; }
  .mascot-face { width: 165px; height: 165px; padding-block-start: 30px; gap: 32px; }
  .mascot-face strong { inset-block-start: 61px; }
  .journey-preview { grid-template-columns: 1fr; }
  .activity-card { min-height: 430px; padding: 22px 15px; border-radius: 25px; }
  .activity-topline { grid-template-columns: 46px 1fr 46px; }
  .icon-button, .sound-button { width: 46px; height: 46px; }
  .hands-stage { grid-template-columns: 1fr; }
  .finger-row { min-height: 135px; }
  .finger { width: min(46px, 11vw); transform: scaleY(0.8); transform-origin: bottom; }
  .finger:hover { transform: scaleY(0.8) translateY(-3px); }
  .dot-groups { gap: 10px; }
  .dot-group { min-height: 145px; padding: 16px; gap: 8px; }
  .dot { width: 31px; height: 31px; }
  .ten-frame { grid-template-columns: repeat(5, min(14vw, 58px)); }
  .ten-cell { width: min(14vw, 58px); height: min(14vw, 58px); }
  .ten-cell::after { width: 68%; height: 68%; }
  .group-grid { grid-template-columns: repeat(2, minmax(90px, 1fr)); }
  .path-list { grid-template-columns: 1fr; }
  .path-card { grid-template-columns: 58px 1fr auto; min-height: 120px; padding: 17px; }
  .path-number { width: 52px; height: 52px; }
  .finish-summary { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
