/* ---------------------------------------------------------------- answer widgets (js/widgets.js)
   A widget is the last thing in the question's column: it takes all the room that is left there (flex) and sizes its
   parts from that room with container units (cqw / cqh – each time with a plain size first for older browsers).
   Colours, radii and shadows follow style.css and models.css. Every class starts with w-. */

.w-root {
  flex: 1 1 100vh; min-height: 240px; width: min(96vw, 1080px); max-width: 100%;
  container-type: size;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  position: relative;
}
/* ✓ pressed too early: a little hop (instead of the big pop-in of style.css .bounce) */
.w-root.bounce { animation: wNudge .5s ease-out; }
.w-root.shake { animation: shake .45s ease-in-out; }
/* the big number above a widget gets a bit smaller, so the widget has room */
.q-col > .q-number:has(+ .w-root) { font-size: min(12vmin, 92px); padding: 0 30px; border-radius: 28px; }

/* ---------------------------------------------------------------- number tiles (order, sort) and their places */
.w-tile, .w-seat, .w-slot { font-size: clamp(26px, 6.5vmin, 58px); font-size: clamp(26px, min(9cqw, 12cqh), 62px); }
.w-tile {
  position: relative; display: inline-grid; place-items: center; flex: none;
  min-width: calc(var(--chars, 2) * .62em + 1.1em); height: 1.62em; padding: 0 .3em; border-radius: .42em;
  font-weight: 700; line-height: 1; color: #fff; text-shadow: 0 .05em 0 rgba(0, 0, 0, .18);
  background: radial-gradient(circle at 30% 22%, color-mix(in srgb, var(--cc, var(--purple)) 42%, #fff), var(--cc, var(--purple)) 64%);
  box-shadow: 0 .1em 0 color-mix(in srgb, var(--cc, var(--purple)) 65%, #000), 0 .2em .36em rgba(43, 35, 80, .16);
  cursor: grab; touch-action: none; transition: transform .15s, box-shadow .15s, opacity .2s, filter .2s;
}
.w-tile .w-lab { pointer-events: none; }
.w-tile .ku { line-height: 1.1; }
/* lifted by a tap (sort): it floats until a basket is tapped */
.w-tile.w-picked { z-index: 2; box-shadow: 0 0 0 .08em #fff, 0 0 0 .17em var(--yellow), 0 .3em .5em rgba(43, 35, 80, .24); animation: wBob 1s ease-in-out infinite; }
.w-tile.w-ok { box-shadow: 0 0 0 .08em #fff, 0 0 0 .17em var(--green), 0 .2em .36em rgba(43, 35, 80, .16); animation: wHop .5s ease-out; }
.w-tile.w-bad { filter: saturate(.55); box-shadow: 0 0 0 .08em #fff, 0 0 0 .17em var(--red); animation: shake .45s ease-in-out 2; }
.w-tile.w-jump { animation: wHop .5s ease-out backwards; animation-delay: calc(var(--d, 0) * 70ms); }
/* carried: the tile stays faint at home while its copy follows the finger */
.w-tile.w-lifted { opacity: .25; transform: scale(.9); }
.w-seat, .w-slot { display: grid; place-items: center; flex: none; min-width: calc(var(--chars, 2) * .62em + 1.1em); height: 1.62em; border-radius: .42em; }
.w-seat.w-empty { background: rgba(43, 35, 80, .06); box-shadow: inset 0 .05em .12em rgba(43, 35, 80, .12); }
.w-slot { background: rgba(255, 255, 255, .85); outline: .07em dashed #a78bfa; outline-offset: -.07em; transition: background .2s, outline-color .2s; }
.w-slot.w-full { background: transparent; outline-color: transparent; }
.w-slot.w-over { background: #fff7c2; outline: .09em solid var(--yellow); outline-offset: .06em; }
.w-tray {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: clamp(10px, 2.6vw, 28px); max-width: 100%;
  padding: 12px 18px; border-radius: 28px; background: rgba(255, 255, 255, .5); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85);
  transition: box-shadow .2s, opacity .3s;
}
.w-tray.w-over { box-shadow: inset 0 0 0 4px var(--yellow); }
.w-locked .w-tile { pointer-events: none; cursor: default; }

/* copies on top of everything: a carried tile, blocks that melt or go away */
.w-fx { position: fixed; z-index: 300; margin: 0 !important; pointer-events: none; }
.w-fx .m-blk { animation: none; }
.w-ghost { transition: none; opacity: .96; cursor: grabbing; box-shadow: 0 .14em 0 rgba(0, 0, 0, .18), 0 .5em 1em rgba(43, 35, 80, .3); }
.w-melt { animation: wMelt .55s ease-in forwards; animation-delay: calc(.12s + var(--d, 0) * 28ms); }
.w-gone { animation: wGone .28s ease-in forwards; }

/* ---------------------------------------------------------------- build a number with blocks */
.w-build { gap: 12px; }
.w-mat {
  --u: .5; --ov: 2.5px;                                  /* the scale of the blocks (js: as big as the piles allow) */
  flex: 1 1 0; min-height: 0; width: 100%; max-width: 1000px;
  display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: clamp(6px, 1.4vw, 14px);
  direction: ltr;                                        /* hundreds on the left, ones on the right – in both styles */
}
/* the place colours of models.css (column sums, the place-value chart) */
.w-kh { --pc: var(--p-h, #fdf2cf); }
.w-kt { --pc: var(--p-t, #fde7f1); }
.w-ko { --pc: var(--p-o, #e2f1fd); }
.w-bcol {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border-radius: 24px; background: linear-gradient(180deg, #fff 10%, var(--pc, #fff));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .9), var(--shadow); transition: box-shadow .3s;
}
.w-bcol.w-good { box-shadow: inset 0 0 0 4px var(--green), var(--shadow); }
.w-bcol.w-off { box-shadow: inset 0 0 0 4px #fb7185, var(--shadow); }
.w-bhead {
  flex: none; text-align: center; white-space: nowrap; overflow: hidden;
  font-size: clamp(15px, 3vmin, 26px); font-size: clamp(15px, 4.4cqh, 28px); line-height: 1.6;
  background: linear-gradient(180deg, #ffc65e, #ff9f1c); color: #5b2400;
}
.w-pile { flex: 1 1 0; min-height: 0; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
/* the blocks stand on the mat; a new row starts above the full one */
.w-stack { display: flex; flex-wrap: wrap-reverse; align-content: flex-start; justify-content: center; width: 100%; padding: var(--ov); }
.w-so { justify-content: flex-start; }
.w-blk {
  flex: none; width: calc(var(--vw) * var(--u) * 1px); height: calc(var(--vh) * var(--u) * 1px);
  max-width: none; max-height: none; margin: calc(var(--ov) * -1); pointer-events: none;
}
.w-blk.w-arrive { animation: wArrive .65s cubic-bezier(.3, 1.25, .5, 1) .42s backwards; }
.w-steps { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px; direction: ltr; }
.w-step {
  height: clamp(50px, 8vmin, 72px); height: clamp(50px, 13cqh, 74px); border-radius: 18px;
  display: grid; place-items: center; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; line-height: 1; color: #fff;
  font-size: clamp(30px, 5vmin, 46px); font-size: clamp(30px, 9cqh, 48px); text-shadow: 0 2px 0 rgba(0, 0, 0, .15);
  transition: transform .08s, box-shadow .08s; touch-action: manipulation;
}
.w-plus { background: var(--green); box-shadow: 0 5px 0 #15803d; }
.w-minus { background: var(--orange); box-shadow: 0 5px 0 #c2410c; }
.w-step:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.w-step.w-hint { outline: 4px solid var(--yellow); outline-offset: 1px; animation: wBeckon .9s ease-in-out infinite; }
.w-build.w-locked .w-step { opacity: .3; }
/* the built number: one digit under each column */
.w-digits {
  flex: none; width: 100%; max-width: 1000px; display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr));
  gap: clamp(6px, 1.4vw, 14px); padding: 4px; direction: ltr; border-radius: 22px; background: #fff; box-shadow: var(--shadow);
  cursor: pointer; transition: background .3s, box-shadow .3s;
}
.w-digit {
  text-align: center; border-radius: 16px; background: var(--pc, #fff); color: var(--ink); font-weight: 700; line-height: 1.2;
  font-size: clamp(28px, 6vmin, 64px); font-size: clamp(28px, 10cqh, 68px); transition: opacity .2s, color .3s;
}
.w-digit.ku { line-height: 1.15; }
.w-digit.w-zero { opacity: .28; }
.w-digits.w-say { animation: pulse .5s ease-in-out; }
.w-build.w-done .w-digits { background: #dcfce7; box-shadow: 0 0 0 4px #86efac, var(--shadow); }
.w-build.w-done .w-digit { color: #15803d; }

/* ---------------------------------------------------------------- set the clock */
.w-face {
  position: relative; width: min(84vw, 50vh, 480px); width: min(100cqw, 100cqh, 540px); aspect-ratio: 1;
  border-radius: 50%; touch-action: none; transition: box-shadow .3s;
}
.w-face .m-clock { width: 100%; height: 100%; max-width: none; max-height: none; }
/* the small hand's knob (like the big hand's knob of models.css, in the small hand's red) */
.w-knob {
  fill: rgba(244, 63, 94, .16); stroke: #f43f5e; stroke-width: 2; stroke-dasharray: 4 3;
  transform-box: fill-box; transform-origin: center; animation: m-breathe 1.4s ease-in-out infinite;
}
.w-face.w-small .w-knob { animation: none; fill: rgba(244, 63, 94, .32); }
.w-face.w-small .m-hh, .w-face .m-clock.m-drag .m-mh { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 7px rgba(250, 204, 21, .9)); }
.w-clock .m-hand.w-hint { animation: wHandHint .65s ease-in-out 4; }
.w-clock.w-locked .w-face { pointer-events: none; }
.w-clock.w-locked .w-knob, .w-clock.w-locked .m-grab { display: none; }
.w-clock.w-done .w-face { box-shadow: 0 0 0 8px rgba(34, 197, 94, .35), 0 0 30px rgba(34, 197, 94, .3); }

/* ---------------------------------------------------------------- put numbers in order */
.w-order { gap: clamp(16px, 5vmin, 44px); }
/* the places stand on steps: from small to big (or big to small) */
.w-slots { display: flex; align-items: flex-end; justify-content: center; gap: clamp(10px, 3.4vw, 40px); max-width: 100%; }
.w-cell { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.w-stair {
  width: 72%; height: calc(var(--k, 1) * 40px); height: calc(var(--k, 1) * clamp(18px, 11cqh, 60px));
  border-radius: 12px 12px 4px 4px; background: linear-gradient(180deg, #ddd6fe, #a78bfa); box-shadow: 0 4px 0 #8b5cf6;
}
.w-order.w-done .w-slot .w-tile { animation: wHop .55s ease-out backwards; animation-delay: calc(var(--d, 0) * 110ms); }

/* ---------------------------------------------------------------- sort into baskets */
.w-sort { gap: clamp(12px, 3.5vmin, 30px); }
.w-sort .w-tile { --cc: var(--purple); }
.w-sort.w-allin .w-tray { opacity: .55; }
.w-baskets { display: grid; grid-template-columns: repeat(var(--nb, 2), minmax(0, 1fr)); gap: clamp(10px, 3vw, 30px); width: 100%; max-width: 920px; }
.w-basket {
  --bc: var(--green);
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0;
  min-height: clamp(150px, 30vh, 300px); min-height: clamp(150px, 46cqh, 330px);
  padding: 10px 8px 6px; border-radius: 30px; cursor: pointer;
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--bc) 8%, #fff) 0 12px, color-mix(in srgb, var(--bc) 16%, #fff) 12px 24px);
  box-shadow: inset 0 0 0 5px color-mix(in srgb, var(--bc) 55%, #fff), var(--shadow);
  transition: transform .15s, box-shadow .2s;
}
.w-basket:active { transform: scale(.98); }
.w-basket.w-over { transform: scale(1.04); box-shadow: inset 0 0 0 6px var(--yellow), var(--shadow); }
.w-sort.w-picking .w-basket { animation: wInvite 1.1s ease-in-out infinite; }
.w-btag {
  font-size: clamp(22px, 5vmin, 40px); font-size: clamp(22px, min(6.5cqw, 9cqh), 44px); line-height: 1.55;
  padding: 0 .7em; border-radius: 1em; color: #fff; background: var(--bc); text-shadow: 0 .05em 0 rgba(0, 0, 0, .15);
  box-shadow: 0 .1em 0 color-mix(in srgb, var(--bc) 65%, #000);
}
.w-bin {
  flex: 1; width: 100%; min-height: 1.75em; display: flex; flex-wrap: wrap; align-items: center; align-content: center; justify-content: center; gap: 8px;
  font-size: clamp(20px, 4.4vmin, 40px); font-size: clamp(20px, min(6cqw, 8cqh), 44px);
}
.w-bin .w-tile { font-size: inherit; }
.w-bpic { font-size: clamp(30px, 7vmin, 60px); font-size: clamp(30px, 10cqh, 66px); line-height: 1.05; pointer-events: none; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .12)); }
.w-sort.w-done .w-bin .w-tile { animation: wHop .55s ease-out; }

/* ---------------------------------------------------------------- a place on the number line */
.w-line { gap: clamp(14px, 5vmin, 40px); }
.w-nlbox { width: 100%; max-width: 1060px; min-height: 0; display: flex; justify-content: center; }
.w-nlbox .m-nl { width: 100%; height: auto; max-width: none; max-height: 56vh; max-height: 64cqh; }
.w-line .m-nl.w-look { animation: wLook .7s ease-in-out; }
.m-nl-pin.w-drop > * { animation: wPinDrop .4s cubic-bezier(.3, 1.5, .5, 1); }
.w-nudges { display: flex; justify-content: center; gap: clamp(36px, 14vw, 140px); direction: ltr; }
.w-nudge {
  width: clamp(62px, 9vmin, 84px); width: clamp(62px, 17cqh, 88px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; color: var(--purple); background: #fff;
  box-shadow: 0 6px 0 #ddd6fe, 0 10px 18px rgba(43, 35, 80, .1); transition: transform .1s, opacity .2s; touch-action: manipulation;
}
.w-nudge svg { width: 52%; height: 52%; }
.w-nudge:active { transform: translateY(4px); box-shadow: 0 2px 0 #ddd6fe; }
.w-line:not(.w-chosen) .w-nudge { opacity: .4; }
.w-nudge.w-hint { color: #d97706; background: #fff7c2; box-shadow: 0 6px 0 #fcd34d, 0 0 0 6px rgba(250, 204, 21, .55); animation: pulse .8s ease-in-out infinite; }
.w-line.w-locked .m-nl { pointer-events: none; }
.w-line.w-locked .w-nudges { visibility: hidden; }

/* ---------------------------------------------------------------- a number on the hundred chart */
.w-hcbox { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.w-chart .m-hc { width: min(92vw, 60vh, 760px); width: min(100cqw, calc(100cqh * 10 / var(--rows, 10)), 780px); }
.w-chart .m-hcc.w-row { background: #fff3b0; box-shadow: inset 0 0 0 .4cqi #facc15; }
.w-chart .m-hcc.w-pick { z-index: 2; background: var(--purple); color: #fff; transform: scale(1.16); box-shadow: 0 0 0 .5cqi #fff, 0 .8cqi 1.6cqi rgba(43, 35, 80, .3); }
.w-chart .m-hcc.w-bad { background: var(--red); color: #fff; animation: shake .45s ease-in-out 2; }
.w-chart.w-done .m-hcc.w-pick { background: var(--green); }
.w-chart.w-locked .m-hc { pointer-events: none; }

/* ---------------------------------------------------------------- colour a fraction */
.w-shapebox { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.w-shade .m-fracshape {
  width: min(76vw, 44vh, 460px); width: min(100cqw, calc(100cqh * var(--vw, 1) / var(--vh, 1)), 480px);
  height: auto; max-width: none; max-height: none;
}
.w-shade .m-part.w-paint { transform-box: fill-box; transform-origin: center; animation: wPaint .45s ease-out; }
.w-shade .m-part.w-hint { transform-box: fill-box; transform-origin: center; animation: wWobble .5s ease-in-out 3; }
.w-shade.w-locked .m-fracshape { pointer-events: none; cursor: default; }
.w-shade.w-done .m-fracshape { filter: drop-shadow(0 0 12px rgba(34, 197, 94, .55)); }

/* ---------------------------------------------------------------- phones held upright */
@media (max-width: 600px) {
  .q-col > .q-number:has(+ .w-root) { font-size: min(17vw, 76px); padding: 0 20px; border-radius: 22px; }
  .w-root { gap: 10px; min-height: 200px; }
  .w-tray { padding: 8px 10px; border-radius: 22px; }
  .w-bcol { border-radius: 18px; }
  .w-steps { gap: 4px; padding: 5px 4px; }
  .w-step { border-radius: 14px; }
  .w-digits { border-radius: 18px; }
  .w-digit { border-radius: 12px; }
  .w-basket { border-radius: 22px; padding: 8px 6px 6px; }
}

/* less motion: things are simply there */
@media (prefers-reduced-motion: reduce) {
  .w-fx:not(.w-ghost) { display: none; }
  .w-knob { animation: none; }
}

@keyframes wNudge { 0%, 100% { transform: none; } 30% { transform: translateY(-12px); } 60% { transform: translateY(4px); } }
@keyframes wBob { 0%, 100% { transform: translateY(-.16em) scale(1.08); } 50% { transform: translateY(-.28em) scale(1.08); } }
@keyframes wHop { 0%, 100% { transform: none; } 40% { transform: translateY(-.32em) scale(1.06); } 70% { transform: translateY(.04em); } }
@keyframes wInvite { 0%, 100% { transform: none; } 50% { transform: scale(1.025); } }
@keyframes wBeckon { 0%, 100% { transform: none; } 50% { transform: translateY(-4px); } }
@keyframes wMelt { 0% { transform: none; opacity: 1; } 35% { transform: scale(1.2); opacity: 1; filter: brightness(1.35) drop-shadow(0 0 6px #fff); } 100% { transform: scale(.1); opacity: 0; } }
@keyframes wGone { to { transform: translateY(-30%) scale(.4); opacity: 0; } }
@keyframes wArrive { 0% { transform: translate(var(--fx, 0px), var(--fy, 0px)) scale(.35); opacity: 0; } 18% { opacity: 1; } 100% { transform: none; opacity: 1; } }
@keyframes wHandHint { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 10px #f43f5e); } }
@keyframes wPinDrop { 0% { transform: translateY(-40px); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes wLook { 0%, 100% { transform: none; } 35% { transform: scale(1.03); } }
@keyframes wPaint { 0% { transform: scale(.88); } 60% { transform: scale(1.06); } 100% { transform: none; } }
@keyframes wWobble { 0%, 100% { transform: none; } 30% { transform: rotate(-5deg) scale(1.04); } 70% { transform: rotate(5deg) scale(1.04); } }
