*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --ink: #2d2552;
  --muted: #6d6694;
  --sky1: #d9f1ff;
  --sky2: #fff3d6;
  --pink: #ff9cc7;
  --orange: #ff9f40;
  --yellow: #ffd94a;
  --green: #7fdca2;
  --blue: #8ccbff;
  --purple: #b9a6ff;
  --fa: #e8457f;   /* first number */
  --fb: #2a8ee6;   /* second number */
  --fc: #1fa863;   /* answer */
  --edge: rgba(45, 37, 82, .18);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--sky2) linear-gradient(180deg, var(--sky1), var(--sky2) 70%) fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, a { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
:focus-visible { outline: 4px solid var(--fb); outline-offset: 3px; }

/* Header */
.bar {
  display: flex; align-items: center; gap: 10px;
  max-width: 760px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
}
.logo { font-weight: 900; font-size: 22px; text-decoration: none; white-space: nowrap; }
.logo .x {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; margin-right: 8px;
  border-radius: 10px; background: var(--fa); color: #fff;
  transform: rotate(-8deg);
}
.bar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill { background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 900; box-shadow: 0 3px 0 var(--edge); white-space: nowrap; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 0 var(--edge);
  font-size: 20px; text-decoration: none;
}
@media (max-width: 400px) { .logo { font-size: 18px; } .logo .x { width: 28px; height: 28px; } }

main { max-width: 760px; margin: 0 auto; padding: 0 16px 48px; }

/* Ollie the owl */
.guide { display: flex; align-items: flex-end; gap: 10px; margin: 6px 0 18px; }
.owl { font-size: 56px; line-height: 1; flex: none; transform-origin: 50% 100%; }
.owl.talk { animation: talk .6s ease; }
@keyframes talk {
  25% { transform: rotate(-8deg) scale(1.06); }
  50% { transform: rotate(6deg); }
  75% { transform: rotate(-3deg); }
}
.bubble {
  position: relative; flex: 1; min-height: 58px;
  text-align: left; background: #fff; border-radius: 22px;
  padding: 14px 46px 14px 18px;
  font-size: clamp(17px, 4.4vw, 21px); font-weight: 700; line-height: 1.35;
  box-shadow: 0 4px 0 var(--edge);
}
.bubble::before {
  content: ""; position: absolute; left: -11px; bottom: 16px;
  border-style: solid; border-width: 10px 12px 10px 0;
  border-color: transparent #fff transparent transparent;
}
.bubble::after { content: "🔈"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 20px; opacity: .55; }

h2 { font-size: 28px; margin: 0 0 14px; text-align: center; }

/* Home */
.menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 20px 10px 16px; border-radius: 26px;
  background: var(--c); text-decoration: none;
  font-weight: 900; font-size: 21px; text-align: center;
  box-shadow: 0 7px 0 var(--edge);
  transition: transform .12s, box-shadow .12s;
}
.card:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--edge); }
@media (hover: hover) { .card:hover { transform: translateY(-3px); } }
.card .emoji { font-size: 54px; line-height: 1.15; }
.card .sub { font-size: 14px; font-weight: 700; opacity: .7; }
.card.wide { grid-column: 1 / -1; }
.card .sticker {
  position: absolute; top: -10px; right: -6px; font-size: 34px;
  transform: rotate(12deg) scale(0);
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1);
}
.card.done .sticker { transform: rotate(12deg) scale(1); }
@media (min-width: 640px) {
  .menu { grid-template-columns: repeat(3, 1fr); }
  .card.wide { grid-column: auto; }
}

/* Shared pieces */
.stage {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px;
  min-height: 130px; padding: 14px 8px;
  background: rgba(255, 255, 255, .55); border-radius: 26px;
}
.plate {
  width: clamp(84px, 26vw, 112px); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 56%, #ece7fb 57%, #fff 70%, #e3dcf7 71%);
  box-shadow: 0 5px 0 var(--edge);
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  padding: 12px;
  transition: transform .2s, box-shadow .2s;
}
.plate.active { transform: scale(1.08); box-shadow: 0 0 0 5px var(--yellow), 0 5px 0 var(--edge); }
.item { position: relative; font-size: clamp(17px, 5vw, 23px); line-height: 1.15; transition: transform .2s; }
.item.lit { transform: scale(1.2); }
.item.lit::after {
  content: attr(data-n);
  position: absolute; top: -6px; right: -9px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--fa); color: #fff;
  font-size: 12px; font-weight: 900; line-height: 18px; text-align: center;
}
.nothing { font-size: 22px; font-weight: 800; color: var(--muted); margin: 0; }

.equation { text-align: center; margin: 16px 0 4px; min-height: 96px; }
.words { font-size: 22px; font-weight: 800; color: var(--muted); }
.math { font-size: clamp(40px, 12vw, 60px); font-weight: 900; line-height: 1.15; }
.fa { color: var(--fa); }
.fb { color: var(--fb); }
.fc { color: var(--fc); }
.zero { color: var(--orange); display: inline-block; animation: grow .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes grow { from { transform: scale(0); } }
@keyframes boing { 50% { transform: scale(1.15); } }

/* Steppers */
.controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.stepper { background: #fff; border-radius: 22px; padding: 8px 10px; box-shadow: 0 4px 0 var(--edge); text-align: center; }
.st-label { display: block; font-weight: 800; color: var(--muted); font-size: 15px; margin-bottom: 4px; }
.st-row { display: flex; align-items: center; gap: 6px; }
.st-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--fb); color: #fff;
  font-size: 28px; font-weight: 900; line-height: 1;
  box-shadow: 0 4px 0 #1f6fb5;
}
.st-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1f6fb5; }
.st-btn:disabled { opacity: .3; cursor: default; transform: none; }
.st-val { min-width: 36px; font-size: 34px; font-weight: 900; }

/* Buttons */
.actions { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.go {
  padding: 16px 28px; border-radius: 999px;
  background: var(--fa); color: #fff;
  font-size: 24px; font-weight: 900; text-decoration: none;
  box-shadow: 0 6px 0 #b52e5f;
}
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 #b52e5f; }
.soft {
  display: inline-block; padding: 14px 22px; border-radius: 999px;
  background: #fff; font-size: 19px; font-weight: 800; text-decoration: none;
  box-shadow: 0 5px 0 var(--edge);
}
.soft:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--edge); }
.busy .controls, .busy .actions, .busy .chips { pointer-events: none; opacity: .5; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 14px; }
.chip { padding: 10px 16px; border-radius: 999px; background: #fff; font-weight: 900; font-size: 18px; box-shadow: 0 4px 0 var(--edge); }
.chip[aria-pressed="true"] { background: var(--fc); color: #fff; box-shadow: 0 4px 0 #157a47; }

/* Pond */
.pond {
  position: relative; overflow: hidden;
  padding: 72px 14px 46px; border-radius: 26px;
  background: linear-gradient(#a8e1ff, #6cc4f5);
}
.line { display: flex; align-items: center; }
.pad {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: #9fe0b2; color: #2c6b44;
  font-weight: 900; font-size: 16px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
  transition: background .3s, transform .3s;
}
.pad.on { background: #2fae66; color: #fff; }
.pad.here { transform: scale(1.15); }
.gap { flex: 1; min-width: 8px; border-top: 3px dashed rgba(255, 255, 255, .85); position: relative; }
.gap span {
  position: absolute; left: 50%; top: 24px; transform: translateX(-50%);
  font-size: 13px; font-weight: 900; color: #fff; white-space: nowrap;
}
.frog {
  position: absolute; top: 26px; left: 0;
  transform: translateX(-50%);
  font-size: 42px; line-height: 1;
  transition: left .5s ease-in-out; pointer-events: none;
}
.frog.still { transition: none; }
.frog span { display: inline-block; }
.frog span.jump { animation: jump .5s ease-in-out; }
@keyframes jump { 50% { transform: translateY(-36px) rotate(-12deg); } }
.trail { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; }
.trail span { background: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 900; font-size: 18px; color: var(--fc); }

/* Arrays */
.array-wrap {
  display: grid; place-items: center; min-height: 310px; padding: 16px;
  background: rgba(255, 255, 255, .55); border-radius: 26px;
}
/* Each row is one group: a dashed band, with its running total beside it. */
.array {
  display: flex; flex-direction: column; gap: 8px;
  margin-right: 44px; /* room for the tallies, keeping the bands centred */
  transition: transform .7s cubic-bezier(.5, -.3, .4, 1.4);
}
.array.turn { transform: rotate(90deg); }
.array.snap { transition: none; }
.arow { position: relative; }
.band {
  display: flex; gap: 6px; padding: 6px;
  border: 3px dashed hsl(var(--h) 70% 58%); border-radius: 16px;
  background: hsl(var(--h) 90% 93%);
  transition: transform .2s, box-shadow .2s, background-color .6s, border-color .6s;
}
.arow.lit .band { transform: scale(1.06); box-shadow: 0 0 0 5px var(--yellow); }
.cell {
  width: 34px; height: 34px; border-radius: 10px;
  background-color: hsl(var(--h) 85% 62%); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .13);
  transition: background-color .6s;
}
.tally {
  position: absolute; left: calc(100% + 8px); top: 50%;
  transform: translateY(-50%) scale(0);
  min-width: 34px; padding: 2px 6px; border-radius: 12px;
  background: var(--fc); color: #fff;
  font-size: 18px; font-weight: 900; text-align: center;
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.tally.shown { transform: translateY(-50%) scale(1); }
.array.turn .tally { opacity: 0; }
.before { margin-top: 6px; font-size: 18px; font-weight: 800; color: var(--muted); }
.before b { color: var(--ink); }
.go.blue { background: var(--fb); box-shadow: 0 6px 0 #1f6fb5; }
.go.blue:active { box-shadow: 0 2px 0 #1f6fb5; }

/* Tens */
.tens { display: flex; flex-direction: column; gap: 6px; }
.ten {
  display: grid; grid-template-columns: repeat(10, 18px); gap: 4px;
  padding: 6px 8px; background: #fff; border-radius: 12px; box-shadow: 0 3px 0 var(--edge);
}
.ten i { width: 18px; height: 18px; border-radius: 50%; background: var(--fb); }
.ten i:nth-child(n+6) { background: #8a6cff; }

.rule-title { text-align: center; font-size: 24px; font-weight: 900; margin: 0 0 12px; }

/* Play */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px 10px; border-radius: 26px; background: #fff;
  font-size: 20px; font-weight: 900; box-shadow: 0 7px 0 var(--edge);
}
.mode:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--edge); }
.mode .emoji { font-size: 60px; line-height: 1.1; }
.progress { display: flex; justify-content: center; gap: 6px; margin-bottom: 12px; }
.progress span {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px;
  background: rgba(255, 255, 255, .7); box-shadow: inset 0 0 0 2px var(--edge);
  transition: transform .2s;
}
.progress span.now { background: var(--yellow); transform: scale(1.25); }
.progress span.star::before { content: "⭐"; }
.progress span.ok { background: var(--green); }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 440px; margin: 10px auto 0; }
.choice {
  height: 84px; border-radius: 24px; background: #fff;
  font-size: 40px; font-weight: 900; box-shadow: 0 6px 0 var(--edge);
}
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--edge); }
.choice.right { background: var(--fc); color: #fff; animation: boing .4s; }
.choice.wrong { background: #ffe0e0; color: #c55; opacity: .6; animation: shake .4s; cursor: default; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.end { text-align: center; }
.end .trophy { font-size: 100px; line-height: 1.1; animation: grow .7s cubic-bezier(.3, 1.6, .5, 1); }
.end .earned { font-size: 30px; letter-spacing: 2px; margin: 8px 0; overflow-wrap: anywhere; }

/* Celebration */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.bit { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 200%);
  background: var(--ink); color: #fff;
  padding: 14px 22px; border-radius: 999px;
  font-weight: 900; font-size: 20px; white-space: nowrap;
  transition: transform .4s cubic-bezier(.3, 1.5, .5, 1);
}
.toast.show { transform: translate(-50%, 0); }
.bump { animation: boing .5s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
