/* Math Blocks — "the toy-maker's tray".
   A maple-wood tray lined with warm oat felt (stitched in each operation's colour)
   holds the 3D blocks; below it a cream enamel readout shows the sum, and the
   answers are thick soft-plastic keys that squish when pressed. Calm, warm,
   tactile: kids get big friendly numerals, parents and teachers get a tool that
   looks cared-for. Each operation has its own accent: + tomato, − blue,
   × grape, ÷ mint. Scoped under .mb; the JS (math-blocks.js) builds the DOM. */
.mb {
  --mb-ink: #1f2a44; --mb-ink-soft: #5d6680;
  --mb-tomato: #ff6b4a; --mb-tomato-d: #d4462a;
  --mb-blue: #3fa9ff;   --mb-blue-d: #1d7fd4;
  --mb-sun: #ffc93c;    --mb-sun-d: #df9a00;
  --mb-mint: #2fd08a;   --mb-mint-d: #139a62;
  --mb-grape: #9b6bff;  --mb-grape-d: #6c3fdc;
  --mb-pink: #ff7ac6;   --mb-pink-d: #db4b9c;
  --mb-oops: #c25a12;   --mb-oops-bg: #ffeedd; --mb-oops-edge: #f1bf8e;
  --mb-display: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --mb-body: 'Nunito', system-ui, sans-serif;

  /* materials */
  --mb-cream: #fbf5ea; --mb-cream-2: #f3e9d6;
  --mb-maple: #e2b47a; --mb-maple-2: #cf9a5c; --mb-maple-d: #a8733a; --mb-maple-dd: #7f5428;
  --mb-felt: #efe3cc; --mb-felt-2: #e4d4b6;
  --mb-ivory: #fffdf7; --mb-ivory-2: #f4eee2;

  /* per-operation accent (overridden below) */
  --acc: var(--mb-tomato); --acc-d: var(--mb-tomato-d); --acc-soft: #ffe1d8;

  --mb-noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .32  0 0 0 0 .24  0 0 0 0 .14  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='.32'/></svg>");
  --mb-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='120'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='.006 .22' numOctaves='3' seed='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .42  0 0 0 0 .25  0 0 0 0 .1  0 0 0 1.1 -.25'/></filter><rect width='100%' height='100%' filter='url(%23g)' opacity='.55'/></svg>");
  --mb-fuzz: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='f'><feTurbulence type='turbulence' baseFrequency='.55' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .4  0 0 0 0 .25  0 0 0 .6 0'/></filter><rect width='100%' height='100%' filter='url(%23f)' opacity='.22'/></svg>");

  position: relative; isolation: isolate;
  max-width: 580px; margin: 16px auto; padding: 18px 18px 24px; border-radius: 34px;
  display: flex; flex-direction: column; gap: 14px;
  font-family: var(--mb-body); color: var(--mb-ink); text-align: left;
  /* the maple tray rim */
  background:
    var(--mb-grain),
    linear-gradient(180deg, #ecc48e 0%, var(--mb-maple) 40%, var(--mb-maple-2) 100%);
  background-size: 400px 120px, auto;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.45), inset 0 -3px 0 rgba(0,0,0,.12),
    0 6px 0 var(--mb-maple-d), 0 8px 0 var(--mb-maple-dd),
    0 24px 50px rgba(0,0,0,.45);
  scroll-margin-top: 64px;
  -webkit-tap-highlight-color: transparent;
  animation: mb-settle .7s cubic-bezier(.2,.9,.25,1) backwards;
}
/* cream enamel inner panel, set into the rim */
.mb::before {
  content: ''; position: absolute; inset: 9px; z-index: -1; border-radius: 26px; pointer-events: none;
  background:
    var(--mb-noise),
    radial-gradient(120% 50% at 50% 0%, #fffaf0 0%, transparent 70%),
    linear-gradient(180deg, var(--mb-cream) 0%, var(--mb-cream-2) 100%);
  box-shadow: inset 0 3px 6px rgba(80,50,15,.22), inset 0 -2px 0 rgba(255,255,255,.7), 0 1px 0 rgba(255,255,255,.4);
}
.mb[data-math-blocks="sub"] { --acc: var(--mb-blue);  --acc-d: var(--mb-blue-d);  --acc-soft: #dcefff; }
.mb[data-math-blocks="mul"] { --acc: var(--mb-grape); --acc-d: var(--mb-grape-d); --acc-soft: #ebe1ff; }
.mb[data-math-blocks="div"] { --acc: var(--mb-mint);  --acc-d: var(--mb-mint-d);  --acc-soft: #d6f6e7; }

.mb *, .mb *::before, .mb *::after { box-sizing: border-box; }
.mb [hidden] { display: none !important; }
.mb button { margin: 0; }
.mb button:focus-visible { outline: 4px solid var(--acc-d); outline-offset: 3px; }

@keyframes mb-settle { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes mb-rise { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes mb-pop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }

/* ---------------- the felt play mat ---------------- */
.mb-stage {
  position: relative; height: clamp(230px, 42vh, 380px); border-radius: 24px; overflow: hidden;
  border: 6px solid transparent;
  background:
    var(--mb-fuzz) padding-box,
    radial-gradient(90% 70% at 50% 35%, #f6ecd9 0%, var(--mb-felt) 55%, var(--mb-felt-2) 100%) padding-box,
    var(--mb-grain) border-box,
    linear-gradient(180deg, #edc995, var(--mb-maple-2)) border-box;
  background-size: 140px 140px, auto, 400px 120px, auto;
  box-shadow:
    inset 0 4px 10px rgba(90,60,20,.28), inset 0 0 0 1px rgba(90,60,20,.12),
    0 4px 0 var(--mb-maple-d), 0 10px 18px rgba(80,50,15,.22);
  animation: mb-rise .7s .08s cubic-bezier(.2,.9,.25,1) backwards;
}
/* accent stitching around the mat (drawn under the blocks) */
.mb-stage::before {
  content: ''; position: absolute; inset: 7px; border-radius: 15px; pointer-events: none;
  border: 2px dashed var(--acc); opacity: .55;
  box-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.mb-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.mb-nogl .mb-stage { display: none; }
.mb-hud { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; z-index: 2; }

/* progress meter: a little rail of blocks, one per question */
.mb-pips { display: flex; gap: 4px; flex-wrap: wrap; padding: 5px 6px; border-radius: 12px; background: rgba(255,251,242,.72); box-shadow: inset 0 2px 3px rgba(90,60,20,.18), 0 1px 0 rgba(255,255,255,.7); }
.mb-pips:empty { background: none; box-shadow: none; padding: 0; }
.mb-pip {
  position: relative; width: 16px; height: 16px; border-radius: 5px;
  background: #e2d6c0; box-shadow: inset 0 -2px 0 rgba(90,60,20,.14);
  transition: background .25s, transform .3s cubic-bezier(.3,1.6,.5,1), box-shadow .25s;
  display: grid; place-items: center; font: 900 11px/1 var(--mb-body); color: #fff;
}
.mb-pip.now { background: var(--acc); box-shadow: inset 0 -3px 0 var(--acc-d), 0 0 0 2px rgba(255,255,255,.9); animation: mb-pip 1.1s ease-in-out infinite; }
.mb-pip.ok { background: var(--mb-mint-d); box-shadow: inset 0 -3px 0 #0c7048; transform: scale(1.08); }
.mb-pip.ok::after { content: '✓'; }
.mb-pip.miss { background: #f2b277; box-shadow: inset 0 -3px 0 #d58a45; }
.mb-pip.miss::after { content: ''; width: 5px; height: 5px; border-radius: 50%; background: #fff; }
@keyframes mb-pip { 50% { transform: translateY(-2px) scale(1.12); } }

.mb-icon {
  border: 0; width: 44px; height: 44px; border-radius: 14px; font-size: 19px; cursor: pointer; padding: 0 0 2px;
  background: linear-gradient(180deg, #fffdf7, #f1e8d6); box-shadow: inset 0 1px 0 #fff, 0 3px 0 #d6c4a2, 0 6px 10px rgba(90,60,20,.18);
  transition: transform .08s, box-shadow .08s;
}
.mb-icon:active { transform: translateY(3px); box-shadow: inset 0 1px 0 #fff, 0 0 0 #d6c4a2, 0 2px 4px rgba(90,60,20,.18); }

.mb-toast {
  position: absolute; left: 50%; bottom: 14px; z-index: 3; transform: translate(-50%, 20px) scale(.9); opacity: 0; pointer-events: none;
  font: 21px var(--mb-display); letter-spacing: .01em; color: #fff; padding: 9px 20px 10px; border-radius: 999px; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(180deg, #34405f, var(--mb-ink)); box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 4px 0 #0f1628, 0 10px 18px rgba(0,0,0,.25);
  transition: transform .4s cubic-bezier(.3,1.6,.5,1), opacity .25s;
}
.mb-toast.show { transform: translate(-50%, 0) scale(1); opacity: 1; }

/* ---------------- panels ---------------- */
.mb-start, .mb-panel { display: flex; flex-direction: column; gap: 14px; }
.mb-start > *, .mb-panel > * { animation: mb-rise .5s cubic-bezier(.2,.9,.25,1) backwards; }
.mb-start > :nth-child(2), .mb-panel > :nth-child(2) { animation-delay: .06s; }
.mb-start > :nth-child(3), .mb-panel > :nth-child(3) { animation-delay: .12s; }
.mb-start > :nth-child(n+4), .mb-panel > :nth-child(n+4) { animation-delay: .18s; }

.mb-eyebrow { margin: 0; text-align: center; font: 900 12px var(--mb-body); letter-spacing: .16em; text-transform: uppercase; color: var(--acc-d); }
.mb-title { font: clamp(34px, 9vw, 46px)/1 var(--mb-display); margin: 0; text-align: center; color: var(--mb-ink); text-wrap: balance; letter-spacing: .01em; text-shadow: 0 2px 0 rgba(255,255,255,.8); }
.mb-sym {
  display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; border-radius: .26em; margin-right: .2em; color: #fff;
  background: linear-gradient(180deg, rgba(255,255,255,.28), transparent 50%), var(--sym, var(--acc));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 .1em 0 var(--sym-d, var(--acc-d)), 0 .16em .2em rgba(60,30,10,.25);
  text-shadow: 0 2px 0 var(--sym-d, var(--acc-d));
  transform: rotate(-6deg) translateY(-3px);
}
.mb-lede { margin: 0; text-align: center; font-weight: 800; color: var(--mb-ink-soft); font-size: 17px; }

/* number picker: chunky soft-plastic keys */
.mb-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 10px; padding-bottom: 6px; }
.mb-tile, .mb-ans, .mb-big { transition: transform .1s cubic-bezier(.3,1.4,.5,1), box-shadow .1s ease, background .2s, color .2s, opacity .25s, filter .25s; }
.mb-tile {
  position: relative; min-height: 58px;
  font: clamp(26px, 7.4vw, 34px)/1 var(--mb-display); color: #fff; border: 0; border-radius: 18px; padding: 13px 0 15px; cursor: pointer;
  background: radial-gradient(120% 70% at 30% 10%, rgba(255,255,255,.4), transparent 55%), var(--c);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.45), inset 0 -3px 0 rgba(0,0,0,.08),
    0 6px 0 var(--cd), 0 7px 0 rgba(0,0,0,.18), 0 12px 16px rgba(60,35,10,.22);
  text-shadow: 0 2px 0 var(--cd), 0 0 2px var(--cd);
  animation: mb-rise .45s cubic-bezier(.2,.9,.25,1) backwards;
}
.mb-tile[style*="mb-sun"] { color: #5c3d00; text-shadow: 0 1px 0 rgba(255,255,255,.55); }
.mb-tile:nth-child(1) { animation-delay: .2s; }  .mb-tile:nth-child(2) { animation-delay: .23s; }
.mb-tile:nth-child(3) { animation-delay: .26s; } .mb-tile:nth-child(4) { animation-delay: .29s; }
.mb-tile:nth-child(5) { animation-delay: .32s; } .mb-tile:nth-child(6) { animation-delay: .35s; }
.mb-tile:nth-child(7) { animation-delay: .38s; } .mb-tile:nth-child(8) { animation-delay: .41s; }
.mb-tile:nth-child(9) { animation-delay: .44s; } .mb-tile:nth-child(10) { animation-delay: .47s; }
.mb-tile:nth-child(11) { animation-delay: .5s; } .mb-tile:nth-child(12) { animation-delay: .53s; }
.mb-tile[data-table="mixed"] { background: radial-gradient(120% 70% at 30% 10%, rgba(255,255,255,.22), transparent 55%), #2c3756; }

/* the press: keys sink onto their base and squish a touch */
.mb-tile:active, .mb-ans:active:not(:disabled), .mb-big:active {
  transform: translateY(5px) scale(1.02, .95);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), inset 0 -2px 0 rgba(0,0,0,.08), 0 1px 0 var(--cd), 0 2px 0 rgba(0,0,0,.18), 0 3px 6px rgba(60,35,10,.2);
}
@media (hover: hover) {
  .mb-tile:hover, .mb-ans:hover:not(:disabled), .mb-big:hover { transform: translateY(-2px); filter: brightness(1.04); }
  .mb-tile:active, .mb-ans:active:not(:disabled), .mb-big:active { transform: translateY(5px) scale(1.02, .95); }
}

/* ---------------- the readout: equation on a cream enamel plaque ---------------- */
.mb-question {
  font: clamp(58px, 16.5vw, 86px)/1 var(--mb-display);
  display: flex; justify-content: center; align-items: center; gap: .16em; letter-spacing: .02em;
  padding: 8px 10px 10px; border-radius: 22px;
  background: linear-gradient(180deg, #fffdf8, #f7efdf);
  box-shadow: inset 0 2px 0 #fff, inset 0 -3px 0 rgba(90,60,20,.07), 0 0 0 1px rgba(150,110,60,.18), 0 4px 0 #e2d2b4, 0 8px 14px rgba(90,60,20,.14);
}
.mb-a { color: var(--mb-tomato-d); text-shadow: 0 3px 0 rgba(255,107,74,.28); }
.mb-b { color: var(--mb-blue-d); text-shadow: 0 3px 0 rgba(63,169,255,.28); }
.mb-op { color: var(--mb-ink-soft); font-size: .72em; }
.mb-slot {
  display: inline-grid; place-items: center; min-width: 1.25em; padding: 0 .12em; height: 1.1em; border-radius: .2em;
  background: var(--acc-soft); color: var(--acc-d);
  box-shadow: inset 0 4px 8px rgba(60,35,10,.16), inset 0 0 0 3px rgba(255,255,255,.55);
  outline: 3px dashed var(--acc); outline-offset: -9px;
  animation: mb-wait 1.8s ease-in-out infinite;
}
.mb-slot.filled {
  color: #fff; outline: 0; animation: mb-pop .45s cubic-bezier(.3,1.7,.5,1);
  background: radial-gradient(120% 70% at 30% 10%, rgba(255,255,255,.35), transparent 55%), var(--mb-mint-d);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 5px 0 #0c7048, 0 8px 12px rgba(19,154,98,.3);
  text-shadow: 0 3px 0 #0c7048;
}
@keyframes mb-wait { 50% { transform: translateY(-2px); } }

/* ---------------- answer keys ---------------- */
.mb-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; padding-bottom: 8px; }
.mb-ans {
  position: relative; min-height: 76px;
  font: clamp(44px, 12.6vw, 58px)/1 var(--mb-display); padding: 13px 0 15px; border: 0; border-radius: 22px; cursor: pointer;
  background: radial-gradient(120% 80% at 30% 0%, #fff 0%, var(--mb-ivory) 45%, var(--mb-ivory-2) 100%);
  color: var(--cd);
  box-shadow:
    inset 0 2px 0 #fff, inset 0 -4px 0 rgba(90,60,20,.06), inset 0 0 0 2px color-mix(in srgb, var(--c) 22%, transparent),
    0 7px 0 var(--c), 0 8px 0 var(--cd), 0 14px 18px rgba(60,35,10,.2);
  text-shadow: 0 2px 0 rgba(255,255,255,.9);
  animation: mb-rise .42s cubic-bezier(.2,.9,.25,1) backwards;
}
.mb-ans:nth-child(2) { animation-delay: .05s; }
.mb-ans:nth-child(3) { animation-delay: .1s; }
.mb-ans:nth-child(4) { animation-delay: .15s; }
.mb-ans:active:not(:disabled) { box-shadow: inset 0 2px 0 #fff, inset 0 -3px 0 rgba(90,60,20,.06), 0 2px 0 var(--c), 0 3px 0 var(--cd), 0 4px 8px rgba(60,35,10,.18); }
.mb-ans kbd { position: absolute; top: 8px; left: 12px; font: 800 12px var(--mb-body); color: #b4a98f; }
@media (hover: none) { .mb-ans kbd { display: none; } }
.mb-ans:disabled { cursor: default; }

/* right: mint key, a check badge and a little sparkle */
.mb-ans.right {
  color: #fff; text-shadow: 0 3px 0 #0c7048;
  background: radial-gradient(120% 80% at 30% 0%, rgba(255,255,255,.4), transparent 55%), var(--mb-mint-d);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 7px 0 #0c7048, 0 8px 0 #085236, 0 14px 22px rgba(19,154,98,.35);
  animation: mb-pop .45s cubic-bezier(.3,1.7,.5,1);
}
.mb-ans.right::after, .mb-ans.oops::after {
  position: absolute; top: -8px; right: -6px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font: 900 17px/1 var(--mb-body); text-shadow: none;
  animation: mb-badge .5s .1s cubic-bezier(.3,1.8,.5,1) both;
}
.mb-ans.right::after { content: '✓'; background: #fff; color: var(--mb-mint-d); box-shadow: 0 3px 0 #0c7048, 0 4px 8px rgba(0,0,0,.2); }
.mb-ans.right::before {
  content: ''; position: absolute; inset: -14px; pointer-events: none; border-radius: 30px;
  background:
    radial-gradient(circle, #ffd84d 0 3px, transparent 4px) 8% 20% / 20px 20px no-repeat,
    radial-gradient(circle, #fff 0 2.5px, transparent 3.5px) 92% 12% / 18px 18px no-repeat,
    radial-gradient(circle, #ffd84d 0 2.5px, transparent 3.5px) 96% 86% / 18px 18px no-repeat,
    radial-gradient(circle, #fff 0 3px, transparent 4px) 4% 90% / 20px 20px no-repeat,
    radial-gradient(circle, #ffd84d 0 2px, transparent 3px) 50% 0% / 16px 16px no-repeat;
  animation: mb-sparkle .9s ease-out both;
}
@keyframes mb-sparkle { 0% { opacity: 0; transform: scale(.7); } 30% { opacity: 1; } 100% { opacity: 0; transform: scale(1.15); } }
@keyframes mb-badge { from { transform: scale(0) rotate(-30deg); } to { transform: none; } }

/* try again: warm, soft, never red — an ✗ badge and a gentle wobble */
.mb-ans.oops {
  background: linear-gradient(180deg, #fff6ec, var(--mb-oops-bg)); color: var(--mb-oops); text-shadow: none;
  box-shadow: inset 0 2px 0 #fff, 0 4px 0 var(--mb-oops-edge), 0 5px 0 #d9a170, 0 8px 12px rgba(160,90,30,.15);
  transform: translateY(3px);
  animation: mb-shake .5s ease;
}
.mb-ans.oops::after { content: '✗'; background: #f6a85e; color: #fff; box-shadow: 0 3px 0 #cf7d35, 0 4px 8px rgba(0,0,0,.15); }
.mb-ans.dim { opacity: .42; filter: saturate(.5); }
@keyframes mb-shake { 20%, 60% { transform: translate(-6px, 3px) rotate(-1.5deg); } 40%, 80% { transform: translate(6px, 3px) rotate(1.5deg); } 100% { transform: translateY(3px); } }

.mb-hint { margin: 0; text-align: center; font-weight: 800; font-size: 17px; color: var(--mb-ink-soft); min-height: 1.4em; }
.mb-hint:empty { min-height: 0; margin-top: -14px; }

/* ---------------- big buttons ---------------- */
.mb-big {
  position: relative; font: 24px/1 var(--mb-display); letter-spacing: .01em; color: #fff; border: 0; border-radius: 20px; padding: 17px 22px 19px; cursor: pointer; min-height: 58px;
  --c: #2c3756; --cd: #141c33;
  background: radial-gradient(120% 70% at 30% 0%, rgba(255,255,255,.32), transparent 55%), var(--c);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 6px 0 var(--cd), 0 7px 0 rgba(0,0,0,.2), 0 12px 18px rgba(60,35,10,.22);
  text-shadow: 0 2px 0 var(--cd);
}
.mb-next { --c: var(--acc); --cd: var(--acc-d); align-self: center; min-width: 62%; animation: mb-rise .4s cubic-bezier(.2,.9,.25,1) backwards; }
.mb-go { --c: var(--mb-mint-d); --cd: #0c7048; }
.mb-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding-bottom: 6px; }
.mb-row .mb-big { flex: 1 1 140px; }
/* after a miss the keys tuck in so "Next" stays on screen */
.mb-panel:has(.mb-next:not([hidden])) .mb-ans { min-height: 60px; padding: 10px 0 12px; font-size: clamp(36px, 10vw, 46px); }
.mb-link {
  align-self: center; cursor: pointer; font: 900 16px var(--mb-body); color: var(--acc-d); min-height: 48px; padding: 10px 22px; border-radius: 999px;
  background: rgba(255,255,255,.6); border: 2px solid color-mix(in srgb, var(--acc) 45%, transparent); box-shadow: 0 3px 0 rgba(150,110,60,.18);
  transition: transform .08s, box-shadow .08s;
}
.mb-link::before { content: '↗ '; }
.mb-link:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(150,110,60,.18); }

/* ---------------- the finish ---------------- */
.mb-stars { display: flex; justify-content: center; gap: 12px; font-size: 62px; line-height: 1; padding-top: 4px; }
.mb-stars span { position: relative; color: #e6dac4; text-shadow: 0 4px 0 #d3c3a5; transform: scale(.82); }
.mb-stars span.on {
  color: #ffcc33; text-shadow: 0 2px 0 #ffe27a, 0 5px 0 #d99200, 0 10px 14px rgba(200,130,0,.35);
  animation: mb-star .6s cubic-bezier(.3,1.8,.5,1) both;
}
.mb-stars span:nth-child(2) { transform: scale(.92) translateY(-8px); }
.mb-stars span.on:nth-child(2) { animation-name: mb-star-mid; }
.mb-stars span.on::after {
  content: ''; position: absolute; inset: -12px; pointer-events: none;
  background:
    radial-gradient(circle, #fff 0 2.5px, transparent 3.5px) 0% 10% / 14px 14px no-repeat,
    radial-gradient(circle, #ffd84d 0 3px, transparent 4px) 100% 0% / 16px 16px no-repeat,
    radial-gradient(circle, #fff 0 2px, transparent 3px) 95% 100% / 12px 12px no-repeat;
  animation: mb-sparkle 1s .15s ease-out both;
}
@keyframes mb-star { 0% { transform: scale(.3) rotate(-40deg); } 100% { transform: scale(1); } }
@keyframes mb-star-mid { 0% { transform: scale(.3) rotate(-40deg) translateY(0); } 100% { transform: scale(1.12) translateY(-8px); } }
.mb-done-title { font: clamp(30px, 8vw, 40px)/1.05 var(--mb-display); text-align: center; margin: 0; text-wrap: balance; color: var(--mb-ink); text-shadow: 0 2px 0 rgba(255,255,255,.8); }
.mb-done-stats, .mb-life { text-align: center; margin: 0; font-weight: 800; color: var(--mb-ink-soft); font-size: 17px; }
.mb-done-stats { align-self: center; padding: 8px 16px; border-radius: 14px; background: rgba(255,255,255,.55); box-shadow: inset 0 1px 3px rgba(90,60,20,.15); }
.mb-life { font-size: 15px; }
.mb-life:empty { display: none; }

.mb-tile.mb-challenge { outline: 4px solid #ffb703; outline-offset: 3px; animation: mb-rise .45s backwards, mb-pulse 1.2s .6s ease-in-out infinite; }
@keyframes mb-pulse { 50% { outline-color: rgba(255,183,3,.35); } }

/* ---------------- phones: the tray goes edge to edge ---------------- */
@media (max-width: 560px) {
  .mb {
    width: 100%; max-width: none; margin: 0 0 14px; border-radius: 0; gap: 12px;
    padding: 12px max(6px, env(safe-area-inset-right, 0px)) 22px max(6px, env(safe-area-inset-left, 0px));
    box-shadow: inset 0 2px 0 rgba(255,255,255,.45), inset 0 -3px 0 rgba(0,0,0,.12), 0 6px 0 var(--mb-maple-d), 0 14px 30px rgba(0,0,0,.4);
    scroll-margin-top: 56px;
  }
  .mb::before { inset: 6px 0; border-radius: 0; }
  .mb-stage { height: clamp(220px, calc(100svh - 56px - 362px), 360px); border-width: 5px; border-radius: 20px; }
  .mb-stage::before { inset: 6px; border-radius: 13px; }
  .mb-start, .mb-panel { gap: 12px; padding-inline: 4px; }
  .mb-tiles { gap: 11px 8px; }
  .mb-answers { gap: 13px 10px; }
  .mb-question { padding: 6px 8px 8px; }
  .mb-hint { font-size: 16px; }
  .mb-hint:empty { margin-top: -12px; }
  .mb-panel:has(.mb-next:not([hidden])) .mb-ans { min-height: 58px; padding: 9px 0 11px; }
  .mb-big { font-size: 22px; padding-inline: 14px; }
  .mb-done-stats { font-size: 15px; }
  .mb-stars { font-size: 56px; }
  .mb-panel:has(.mb-next:not([hidden])) .mb-hint { font-size: 15px; }
}
@media (max-width: 560px) and (max-height: 700px) {
  .mb-question { font-size: clamp(52px, 15.5vw, 64px); }
}

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