/* Crush It! (js/arcade/crush.js). Every class starts with .cr- */

/* --u: the size of one cube (the same on every block, so a bigger block really looks bigger); --uf: on a flat pancake, seen from above */
.cr-wrap {
  --u: 22px;
  --uf: 28px;
  --metal: color-mix(in srgb, var(--muted) 35%, white);
  --metal-d: color-mix(in srgb, var(--muted) 75%, var(--ink));
  --yard-h: 300px;
  position: relative; display: grid; gap: 8px; width: min(100%, 600px); margin: 0 auto; padding-bottom: 14px;
}

/* ---------- HUD: the car she is on, the stars she can win, the score ---------- */
.cr-hud { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 14px; font: 700 14px var(--font-ui); color: var(--muted); }
.cr-hud b { color: var(--ink); font-size: 19px; }
.cr-stars { display: inline-flex; gap: 3px; }
.cr-star {
  --f: 0%; width: 24px; height: 24px;
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 59%, 80% 94%, 50% 73%, 20% 94%, 31% 59%, 2% 37%, 38% 36%);
  background: linear-gradient(90deg, var(--sun) var(--f), var(--tile-shadow) var(--f));
}
.cr-star.cr-half { --f: 50%; }
.cr-star.cr-full { --f: 100%; animation: cr-pop-in 0.45s; }
@keyframes cr-pop-in { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: none; } }

/* ---------- the question: the words she reads, and the answer box ---------- */
.cr-ask { display: grid; justify-items: center; gap: 2px; padding: 8px 14px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-soft); text-align: center; }
.cr-words { margin: 0; font: 700 18px/1.3 var(--font-read); color: var(--ink); }
.cr-sum { font: 900 30px/1.2 var(--font-ui); color: var(--grape-d); white-space: nowrap; }
.cr-sum[hidden] { display: none; }
.cr-box {
  display: inline-block; min-width: 1.3em; padding: 0 8px; border-radius: 12px; text-align: center;
  border: 3px dashed var(--grape); color: var(--grape); background: color-mix(in srgb, var(--grape) 8%, white);
}
.cr-box.cr-filled { border-style: solid; border-color: var(--green-d); color: var(--green-d); background: color-mix(in srgb, var(--green) 18%, white); animation: cr-pop-in 0.45s; }

/* ---------- the yard: the press, the belt, and what is on it ---------- */
.cr-yard {
  position: relative; height: var(--yard-h); overflow: hidden; border-radius: var(--radius);
  background:
    radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--sun) 35%, white) 0 22px, transparent 23px),
    linear-gradient(color-mix(in srgb, var(--sky) 26%, white), color-mix(in srgb, var(--sky) 10%, white) 70%, color-mix(in srgb, var(--lime) 22%, white) 70%);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--sky) 55%, white), var(--shadow-soft);
}
.cr-post { position: absolute; top: 0; bottom: 24px; width: 16px; border-radius: 0 0 6px 6px; background: linear-gradient(90deg, var(--metal), var(--card) 40%, var(--metal)); box-shadow: inset 0 0 0 2px var(--metal-d); z-index: 1; }
.cr-post-l { left: 10px; }
.cr-post-r { right: 10px; }
.cr-beam {
  position: absolute; left: 0; right: 0; top: 0; height: 30px; z-index: 4;
  background: repeating-linear-gradient(-45deg, var(--sun) 0 14px, var(--ink) 14px 24px);
  box-shadow: 0 3px 0 var(--sun-d), inset 0 -3px 0 color-mix(in srgb, var(--ink) 40%, var(--sun-d));
}
/* the head: a rod (it runs up behind the beam) and the plate; --drop is set as it comes down */
.cr-head { position: absolute; left: 34px; right: 34px; top: 30px; height: 20px; z-index: 3; transition: transform 0.19s cubic-bezier(0.55, 0, 1, 0.45); }
.cr-yard.cr-down .cr-head { transform: translateY(var(--drop, 120px)); }
.cr-yard:not(.cr-down) .cr-head { transition: transform 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
.cr-rod { position: absolute; left: 50%; bottom: 100%; width: 30px; height: 320px; transform: translateX(-50%); border-radius: 4px 4px 0 0; background: linear-gradient(90deg, var(--metal-d), var(--card) 45%, var(--metal)); box-shadow: inset 0 0 0 2px var(--metal-d); }
.cr-plate { position: absolute; inset: 0; border-radius: 6px 6px 10px 10px; background: repeating-linear-gradient(-45deg, var(--sun) 0 12px, var(--ink) 12px 20px); box-shadow: inset 0 0 0 3px var(--ink), 0 4px 0 color-mix(in srgb, var(--ink) 25%, transparent); }

/* the floor of the press: the car before, the block after */
.cr-floor { position: absolute; left: 30px; right: 30px; top: 58px; bottom: 24px; z-index: 2; display: flex; align-items: flex-end; justify-content: center; }
.cr-belt {
  position: absolute; left: 0; right: 0; bottom: 0; height: 24px; z-index: 2; display: flex; align-items: center; justify-content: space-around; padding: 0 8px;
  background: var(--ink); background-image: repeating-linear-gradient(90deg, transparent 0 18px, color-mix(in srgb, var(--ink) 70%, var(--card)) 18px 22px);
}
.cr-belt i { width: 14px; height: 14px; border-radius: 50%; background: var(--metal); box-shadow: inset 0 0 0 3px var(--metal-d); }
.cr-yard.cr-rolling .cr-belt { animation: cr-belt 0.65s linear; }
@keyframes cr-belt { from { background-position: 0 0; } to { background-position: 66px 0; } }

/* ---------- the toy cars ---------- */
.cr-k-sky { --car: var(--sky); --car-d: var(--sky-d); }
.cr-k-rose { --car: var(--rose); --car-d: var(--rose-d); }
.cr-k-sun { --car: var(--sun); --car-d: var(--sun-d); }
.cr-k-grape { --car: var(--grape); --car-d: var(--grape-d); }
.cr-k-lime { --car: var(--lime); --car-d: var(--lime-d); }
.cr-k-teal { --car: var(--teal); --car-d: var(--teal-d); }
.cr-cars { display: flex; align-items: flex-end; justify-content: space-around; width: 100%; }
.cr-cars.cr-roll { animation: cr-roll 0.65s cubic-bezier(0.2, 0.9, 0.3, 1.1); }
@keyframes cr-roll { from { transform: translateX(-120%); } to { transform: none; } }
.cr-car { display: block; width: 132px; flex: none; }
.cr-car-art { display: block; width: 100%; height: auto; overflow: visible; transform-origin: 50% 100%; }
.cr-cars .cr-car .cr-car-art { animation: cr-idle 1.4s ease-in-out infinite; }
@keyframes cr-idle { 0%, 100% { transform: none; } 50% { transform: translateY(-2px) scaleY(1.02); } }
.cr-car.cr-squash .cr-car-art { animation: cr-squash 0.33s ease-out forwards; }
@keyframes cr-squash { 0% { transform: none; } 45% { transform: scale(1.22, 0.3); } 70% { transform: scale(1.15, 0.36); } 100% { transform: scale(1.2, 0.32); } }
.cr-body { fill: var(--car); stroke: var(--car-d); stroke-width: 3; stroke-linejoin: round; }
.cr-bed { fill: var(--car-d); stroke: color-mix(in srgb, var(--car-d) 70%, var(--ink)); stroke-width: 3; }
.cr-bed-line { stroke: var(--car); stroke-width: 3; }
.cr-stripe { fill: var(--card); opacity: 0.55; }
.cr-glass, .cr-glass rect { fill: color-mix(in srgb, var(--sky) 30%, white); stroke: var(--car-d); stroke-width: 2.5; }
.cr-eye { fill: var(--ink); }
.cr-shine { fill: var(--card); }
.cr-smile { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.cr-lamp { fill: var(--sun); stroke: var(--sun-d); stroke-width: 1.5; }
.cr-cheek { fill: var(--rose); opacity: 0.7; }
.cr-wheel { fill: var(--ink); }
.cr-hub { fill: var(--metal); }

/* ---------- the blocks of cubes ---------- */
.cr-blocks { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; width: 100%; height: 100%; }
.cr-blocks.cr-pop { animation: cr-block-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); transform-origin: 50% 100%; }
@keyframes cr-block-in { 0% { transform: scale(1.3, 0.3); } 55% { transform: scale(0.92, 1.1); } 100% { transform: none; } }
.cr-block { display: block; padding: 0; border: 0; background: none; font: inherit; max-width: 100%; min-height: 0; touch-action: manipulation; }
button.cr-block { cursor: pointer; border-radius: 14px; }
button.cr-block:focus-visible { outline: 3px solid var(--grape); outline-offset: 2px; }
.cr-block svg { display: block; height: auto; max-width: 100%; max-height: calc(var(--yard-h) - 112px); overflow: visible; }
.cr-top { fill: color-mix(in srgb, var(--car) 55%, white); }
.cr-lf { fill: var(--car); }
.cr-rt { fill: var(--car-d); }
.cr-top, .cr-lf, .cr-rt { stroke: color-mix(in srgb, var(--car-d) 55%, var(--ink)); stroke-width: 0.05; stroke-linejoin: round; }
/* every other layer a shade lighter, so the layers show */
.cr-ly1 .cr-top { fill: color-mix(in srgb, var(--car) 35%, white); }
.cr-ly1 .cr-lf { fill: color-mix(in srgb, var(--car) 75%, white); }
.cr-ly1 .cr-rt { fill: color-mix(in srgb, var(--car-d) 80%, white); }
.cr-ly { transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
.cr-fresh { animation: cr-flash 0.45s ease-out; }
@keyframes cr-flash { from { opacity: 0.2; } to { opacity: 1; } }
/* the flat pancake, seen from above: the rows have a gap between them */
.cr-sq { fill: var(--car); stroke: var(--car-d); stroke-width: 0.06; }
.cr-sq-hi { fill: var(--card); opacity: 0.45; }
.cr-row-bg { fill: transparent; }
.cr-on .cr-row-bg { fill: color-mix(in srgb, var(--green) 28%, white); stroke: var(--green-d); stroke-width: 0.06; }
/* the running total beside a counted row or layer */
.cr-lab rect { fill: var(--green-d); }
.cr-lab text { fill: var(--card); font: 800 0.72px var(--font-ui); text-anchor: middle; }
.cr-tip { font: 700 14px/1 var(--font-read); color: var(--ink); padding: 4px 12px; border-radius: 999px; background: var(--card); box-shadow: 0 2px 0 var(--tile-shadow); white-space: nowrap; }
.cr-tip:not(.cr-done) { animation: cr-nudge 1.6s ease-in-out infinite; }
.cr-tip.cr-done { color: var(--green-d); }

/* Which Is Bigger?: two blocks side by side, their cubes counted after the answer */
.cr-blocks.cr-pair { flex-direction: row; align-items: flex-end; justify-content: space-around; }
.cr-side { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.cr-count { visibility: hidden; font: 800 15px/1 var(--font-read); color: var(--ink); padding: 4px 10px; border-radius: 999px; background: var(--card); white-space: nowrap; }
.cr-counted .cr-count, .cr-right .cr-count { visibility: visible; }
.cr-win .cr-count { background: var(--green-d); color: var(--card); }
.cr-win .cr-block { filter: drop-shadow(0 0 6px var(--sun)) drop-shadow(0 0 2px var(--sun-d)); }

/* the crushed car on fill: a bar of cubes that drops into the bin */
.cr-bar.cr-into-bin { animation: cr-into-bin 1s ease-in forwards; }
@keyframes cr-into-bin { 0%, 55% { transform: none; opacity: 1; } 100% { transform: translateY(70px) scale(0.5); opacity: 0; } }

/* ---------- dust and sparks when the press lands ---------- */
.cr-fx { position: absolute; left: 50%; bottom: 26px; width: 0; height: 0; z-index: 3; pointer-events: none; }
.cr-puff { position: absolute; left: calc(var(--x) - var(--r)); bottom: 0; width: calc(2 * var(--r)); height: calc(2 * var(--r)); border-radius: 50%; background: color-mix(in srgb, var(--muted) 25%, white); opacity: 0; animation: cr-puff 0.7s ease-out var(--d) forwards; }
@keyframes cr-puff { 0% { opacity: 0.95; transform: scale(0.4); } 100% { opacity: 0; transform: translate(calc(var(--x) * 0.6), -26px) scale(1.5); } }
.cr-spark { position: absolute; left: -6px; bottom: 30px; width: 12px; height: 12px; background: var(--sun); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); opacity: 0; animation: cr-spark 0.6s ease-out var(--d) forwards; }
@keyframes cr-spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(10px) scale(0.6); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(110px) scale(1.2); } }
.cr-yard.cr-shake { animation: cr-shake 0.32s; }
@keyframes cr-shake { 20% { transform: translate(-5px, 3px); } 40% { transform: translate(5px, -2px); } 60% { transform: translate(-3px, 2px); } 80% { transform: translate(2px, -1px); } }

/* ---------- the recycling bin (fill) ---------- */
.cr-bin { display: grid; justify-items: center; gap: 6px; padding: 8px 10px 10px; border-radius: var(--radius); background: color-mix(in srgb, var(--green) 16%, white); box-shadow: inset 0 0 0 3px var(--green-d); }
.cr-bin[hidden] { display: none; }
.cr-bin-name { font: 800 16px var(--font-read); color: var(--ink); }
.cr-bin-name b { font: 900 22px var(--font-ui); color: var(--green-d); }
.cr-slots { display: grid; grid-template-columns: repeat(5, 24px) 8px repeat(5, 24px); gap: 4px; }
.cr-slot { width: 24px; height: 24px; border-radius: 6px; background: var(--card); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--green-d) 40%, white); }
.cr-slot:nth-child(10n + 6) { grid-column-start: 7; }
.cr-slot.cr-in { background: var(--car); box-shadow: inset 0 0 0 2px var(--car-d), inset 0 6px 0 color-mix(in srgb, var(--card) 35%, transparent); }
.cr-slot.cr-drop { animation: cr-drop 0.35s cubic-bezier(0.3, 1.4, 0.5, 1) var(--d) backwards; }
@keyframes cr-drop { from { transform: translateY(-34px); opacity: 0; } to { transform: none; opacity: 1; } }
.cr-slot.cr-spill { background: var(--danger); box-shadow: inset 0 0 0 2px var(--danger-d); }
.cr-bin.cr-over .cr-spill { animation: cr-drop 0.35s cubic-bezier(0.3, 1.4, 0.5, 1) var(--d) backwards, cr-hop 0.5s ease-in-out 0.8s 2; }
@keyframes cr-hop { 50% { transform: translateY(-8px) rotate(12deg); } }
.cr-bin.cr-over { box-shadow: inset 0 0 0 3px var(--danger-d); }
.cr-bin.cr-short .cr-slot:not(.cr-in) { box-shadow: inset 0 0 0 3px var(--danger); }

/* ---------- Crush! and the answers ---------- */
.cr-act { display: grid; min-height: 64px; }
.cr-crush { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 64px; font: 900 30px/1 var(--font-ui); color: var(--card); touch-action: manipulation; }
.cr-crush[hidden] { display: none; }
.cr-crush:not(:disabled) { animation: cr-nudge 1.6s ease-in-out infinite; }
@keyframes cr-nudge { 0%, 70%, 100% { transform: none; } 80% { transform: scale(1.05); } 90% { transform: scale(0.98); } }
.cr-btn-art { width: 40px; height: 40px; }
.cr-i-beam, .cr-i-plate { fill: var(--sun); stroke: var(--ink); stroke-width: 2; }
.cr-i-rod { fill: var(--card); stroke: var(--ink); stroke-width: 2; }
.cr-i-cube { fill: var(--card); }
.cr-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cr-choices[hidden] { display: none; }
.cr-choices.cr-in { animation: cr-rise 0.4s ease-out; }
@keyframes cr-rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.cr-choices.cr-three { grid-template-columns: 1fr 0.8fr 1fr; }
.cr-choice { display: grid; place-items: center; gap: 2px; min-height: 58px; padding: 6px 4px; color: var(--ink); font: 900 30px/1 var(--font-ui); touch-action: manipulation; }
.cr-three .cr-choice { font: 800 19px/1.1 var(--font-read); }
.cr-cars-pick .cr-choice { min-height: 88px; padding: 6px 4px 8px; background: var(--card); box-shadow: 0 5px 0 var(--tile-shadow), inset 0 0 0 3px var(--sun); }
.cr-car.cr-mini { width: min(64px, 100%); }
.cr-choice.cr-off { opacity: 0.35; }
.cr-choice.cr-yes { background: var(--green); box-shadow: 0 5px 0 var(--green-d); color: var(--card); }
.cr-no { animation: cr-no 0.32s; }
@keyframes cr-no { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.cr-msg { min-height: 44px; margin: 0; display: grid; place-items: center; text-align: center; font: 700 16px/1.35 var(--font-read); color: var(--ink); }
.cr-wrap.cr-right .cr-yard { box-shadow: inset 0 0 0 4px var(--green-d), var(--shadow-soft); }

/* iPad: more room */
@media (min-width: 700px) {
  .cr-wrap { --u: 30px; --uf: 40px; --yard-h: 390px; gap: 12px; }
  .cr-words { font-size: 22px; }
  .cr-sum { font-size: 40px; }
  .cr-msg { font-size: 19px; }
  .cr-car { width: 176px; }
  .cr-head { left: 48px; right: 48px; height: 24px; }
  .cr-beam { height: 34px; }
  .cr-head { top: 34px; }
  .cr-floor { top: 66px; }
  .cr-tip { font-size: 16px; }
  .cr-count { font-size: 18px; }
  .cr-slots { grid-template-columns: repeat(5, 32px) 12px repeat(5, 32px); gap: 5px; }
  .cr-slot { width: 32px; height: 32px; }
  .cr-choice { min-height: 68px; font-size: 36px; }
  .cr-three .cr-choice { font-size: 22px; }
  .cr-cars-pick .cr-choice { min-height: 104px; }
  .cr-car.cr-mini { width: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .cr-star.cr-full, .cr-box.cr-filled, .cr-no, .cr-crush:not(:disabled), .cr-tip:not(.cr-done), .cr-cars.cr-roll, .cr-cars .cr-car .cr-car-art,
  .cr-blocks.cr-pop, .cr-fresh, .cr-bar.cr-into-bin, .cr-slot.cr-drop, .cr-bin.cr-over .cr-spill, .cr-yard.cr-shake, .cr-yard.cr-rolling .cr-belt, .cr-choices.cr-in { animation: none; }
  .cr-head, .cr-ly { transition: none; }
}
