/*
  The Mighty Arcade's shared menus: each game's title screen and its win card (arcade-ui.js).

  Direction A, "the tile becomes the title" (Phil, Nov 13, 2026; mockups in drtreys.com's
  _review/arcade-menus-2026-11-13/). The tile a child tapped on the Kids Zone opens up into the
  game's first screen: same art, same color. Numbered level buttons carry the stars already earned,
  one big round play button sits low enough for a thumb, and a crew member stands beside it. After a
  win, a crew member cheers over a "You did it!" card. Nothing has to be read to play: the words are
  there for grown-ups and screen readers.

  The game colors are the tiles' own, so they're the same at every practice. The practice shows up as
  its people (assets/crew/crew.json).
*/

/* ---------- each game's colors, from its tile: the rim, a lighter shade, a deep shade
   (the deep shade carries white at 4.5:1 or more, and is 3:1 or more on white) */
[data-game='memory-match']  { --g: #1c89e2; --g-soft: #48a2ea; --g-deep: #0568b7; }
[data-game='tooth-run']     { --g: #ff7700; --g-soft: #ff9533; --g-deep: #b35100; }
[data-game='sugar-bug-pop'] { --g: #cb3580; --g-soft: #d95e9c; --g-deep: #96205b; }
[data-game='jigsaw-puzzle'] { --g: #35cb67; --g-soft: #5fd889; --g-deep: #1d7a3d; }
[data-game='coloring-book'] { --g: #e2a91a; --g-soft: #ecbf4d; --g-deep: #8a5d00; }
[data-game='storybook']     { --g: #c685f1; --g-soft: #d6a6f5; --g-deep: #7a3fb0; }

.arcade-title, .arcade-win {
  --gold: #f6b40e;
  --gold-deep: #9a6700;
  --star-off: #e3e6ec;
  --star-off-line: #8e97a8;
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.arcade-title *, .arcade-win * { box-sizing: border-box; }
/* :where() keeps this reset at zero specificity, so each button's own size and margins win */
:where(.arcade-title, .arcade-win) button {
  font: inherit; margin: 0; padding: 0; border: 0; cursor: pointer; touch-action: manipulation; }
.arcade-title :focus-visible, .arcade-win :focus-visible {
  outline: 4px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 7px #10243f; }

/* stars */
.as-star { width: 1em; height: 1em; display: block; overflow: visible; }
.as-star path { fill: var(--gold); stroke: var(--gold-deep); stroke-width: 6; stroke-linejoin: round; }
.as-star.off path { fill: var(--star-off); stroke: var(--star-off-line); stroke-width: 5; }

/* Puzzle pieces, the jigsaw's mark in place of stars (Phil, Nov 15, 2026): a puzzle is finished or it
   isn't, and a star "out of 3" read as a poor score. One piece per size, filled once that size is
   finished. In a row they lock together, each knob in the next one's hole: the viewBox is 84 wide and
   the pieces sit 60 apart, so each overlaps the one before by 24/84 of its width, with no gap. */
.as-piece { width: 1em; height: 1em; display: block; overflow: visible; flex: none; }
.as-piece + .as-piece { margin-left: -.2857em; }
.as-piece path { fill: var(--gold); stroke: var(--gold-deep); stroke-width: 5; stroke-linejoin: round; }
.as-piece.off path { fill: var(--star-off); stroke: var(--star-off-line); stroke-width: 4; }
/* the size, on the win card's pieces, centered right of the hole: 6.7:1 on the gold, 4.8:1 on the gray */
.as-piece text { font-size: 28px; font-weight: 900; text-anchor: middle; fill: #4a3000; }
.as-piece.off text { fill: #5b6475; }

/* ======================================================= the title screen */
.arcade-title {
  position: fixed; inset: 0; z-index: 50; overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  background: var(--g);
  padding: 0 16px;
}
/* the tile's own lighter arch, carried onto the screen */
.arcade-title::before {
  content: ''; position: absolute; left: -45%; right: -45%; top: 60%; height: 100%;
  border-radius: 50%; background: var(--g-soft);
}
.arcade-title > * { position: relative; }

.at-head { margin: clamp(18px, 6vh, 56px) 0 0; line-height: 0; }
/* A burst of light behind the tile, centered on it, so a tile doesn't melt into a background of its
   own color (Phil, Nov 13, 2026, from the prize-counter mockup). It fades out toward the edges and
   sits under the lighter arch. */
.at-head::before {
  content: ''; position: absolute; z-index: -1; left: 50%; top: 50%; width: 240vmax; height: 240vmax;
  transform: translate(-50%, -50%); pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, .38) 0, rgba(255, 255, 255, .14) 9%, rgba(255, 255, 255, 0) 20%),
    repeating-conic-gradient(rgba(255, 255, 255, .16) 0deg 9deg, rgba(255, 255, 255, 0) 9deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, #000 10%, transparent 30%);
  mask-image: radial-gradient(circle, #000 0, #000 10%, transparent 30%);
}
/* The tiles are 510px: at a phone's 2x that's sharp up to 255px wide, so no bigger. */
.at-tile { width: clamp(150px, 31vh, 255px); height: auto; aspect-ratio: 1; transform: rotate(-4deg);
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, .2)); }

.at-levels { display: flex; gap: clamp(10px, 2vh, 16px); margin-top: clamp(20px, 5.5vh, 48px); }
.at-chip {
  width: clamp(68px, 12vh, 92px); height: clamp(78px, 13.5vh, 104px); border-radius: 22px;
  background: #fff; color: var(--g-deep);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-weight: 900; font-size: clamp(32px, 6vh, 46px); line-height: 1;
  box-shadow: 0 6px 0 var(--g-deep), 0 12px 16px rgba(0, 0, 0, .18);
  transition: transform .12s ease;
}
.at-chip .at-stars { display: flex; gap: 2px; font-size: clamp(13px, 2.2vh, 17px); }
.at-chip[aria-pressed='true'] {
  background: var(--g-deep); color: #fff; transform: translateY(-6px);
  box-shadow: 0 0 0 4px #fff, 0 10px 0 4px rgba(0, 0, 0, .22);
}
.at-chip[aria-pressed='true'] :is(.as-star, .as-piece).off path { fill: rgba(255, 255, 255, .25); stroke: rgba(255, 255, 255, .7); }
.at-chip:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--g-deep); }
.at-chip .at-lock { position: absolute; top: -8px; right: -8px; font-size: 20px; }
/* More than three levels (Sugar Bug Pop's six): rows of three, with a smaller tile and buttons to make
   the room on a phone. */
.at--many .at-tile { width: clamp(130px, 24vh, 220px); }
.at--many .at-levels {
  flex-wrap: wrap; justify-content: center; row-gap: clamp(12px, 2.2vh, 18px);
  max-width: calc(3 * clamp(60px, 10vh, 84px) + 2 * clamp(10px, 2vh, 16px) + 2px);
  margin-top: clamp(16px, 4vh, 36px);
}
.at--many .at-chip { width: clamp(60px, 10vh, 84px); height: clamp(66px, 11vh, 92px); font-size: clamp(28px, 5vh, 40px); border-radius: 20px; }

/* The jigsaw: first a grid of its pictures (no play button: picking one is the next step), then the
   picture it picked in the tile's place. The pictures are the point of the first screen, so it has no
   crew member, a smaller tile, and the pictures take the rest of the height (Phil, Nov 13, 2026: "too
   small"): two columns on a phone, three where the screen is wider. The thumbnails are 640px, sharp
   up to 320px. */
.at--pictures {
  --head: calc(clamp(88px, 16vh, 170px) + 2 * clamp(12px, 3vh, 26px));
  padding-bottom: 16px;
  --cols: 2;
  --pic: min(calc((100vw - 32px - 14px) / 2), calc((100vh - var(--head) - 100px) / 3));
}
@media (min-aspect-ratio: 3/4) {
  .at--pictures {
    --cols: 3;
    --pic: min(calc((100vw - 32px - 28px) / 3), calc((100vh - var(--head) - 84px) / 2));
  }
}
.at--pictures .at-head { margin: clamp(12px, 3vh, 26px) 0; }
.at--pictures .at-tile { width: clamp(88px, 16vh, 170px); }
/* centered in the space under the tile, so a wide screen's spare height splits above and below */
.at-pics {
  display: grid; grid-template-columns: repeat(var(--cols), min(var(--pic), 320px)); gap: 14px;
  margin: auto 0;
}
.at-pic {
  position: relative; display: block; aspect-ratio: 1; border-radius: 20px; overflow: hidden;
  background: #fff; box-shadow: 0 0 0 4px #fff, 0 7px 0 4px var(--g-deep), 0 12px 16px rgba(0, 0, 0, .18);
  transition: transform .12s ease;
}
.at-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.at-pic .at-stars {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; gap: 3px;
  font-size: clamp(15px, 2.6vh, 22px); background: rgba(255, 255, 255, .94); padding: 4px 9px; border-radius: 999px;
}
.at-pic:active { transform: translateY(4px); }
.at-preview { border-radius: 26px; box-shadow: 0 0 0 6px #fff; object-fit: cover; width: clamp(150px, 29vh, 250px); }

/* The jigsaw's pieces: one per size button, a row of three on each picture, no gap between them */
.at--pieces .at-chip .at-stars { font-size: clamp(20px, 3.2vh, 26px); gap: 0; }
.at--pieces .at-pic .at-stars { font-size: clamp(18px, 3vh, 26px); gap: 0; padding: 4px 10px 3px; }

/* What the picked level means, under the buttons (the jigsaw's "12 pieces") */
.at-detail {
  display: flex; align-items: center; gap: 8px; margin: clamp(16px, 3.4vh, 28px) 0 0;
  padding: 8px 18px 8px 14px; border-radius: 999px; background: #fff; color: var(--g-deep);
  font-weight: 800; font-size: clamp(18px, 3vh, 24px); line-height: 1.1;
  box-shadow: 0 4px 0 var(--g-deep);
}
.at-detail svg { width: 1.3em; height: 1.3em; flex: none; }
.at-best { display: flex; gap: 6px; margin-top: clamp(18px, 4.5vh, 36px); font-size: clamp(24px, 4.4vh, 34px);
  background: rgba(0, 0, 0, .18); padding: 8px 16px; border-radius: 999px; }

/* The play button hops from the moment the screen opens, since a level is already picked: playing is
   the next thing to do (Phil, Nov 15, 2026). The button itself stays put, so it's always where a finger
   expects it; its face does the hopping, and its shadow stays on the ground. */
.at-play {
  --hop: clamp(18px, 3.4vh, 30px);   /* how high it hops */
  --hop-t: 1.6s;                      /* one hop, a small bounce, then a rest */
  --hop-wait: .5s;                    /* the screen settles first */
  width: clamp(100px, 17vh, 132px); height: clamp(100px, 17vh, 132px); border-radius: 50%;
  margin-top: auto; margin-bottom: clamp(30px, 9vh, 84px);
  background: none; color: var(--g-deep);
}
.at-play-face {
  position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center;
  background: #fff; box-shadow: 0 9px 0 var(--g-deep);
  transform-origin: 50% 100%;
  animation: at-hop var(--hop-t) var(--hop-wait) infinite, at-squash var(--hop-t) var(--hop-wait) infinite;
  transition: translate .08s ease-out, scale .08s ease-out, box-shadow .08s ease-out;
}
.at-play-face svg { width: 46%; height: 46%; margin-left: 8%; }
.at-play-shadow {
  position: absolute; left: 4%; right: 4%; top: calc(100% - 6px); height: 28px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .3), rgba(0, 0, 0, .14) 60%, rgba(0, 0, 0, 0));
  animation: at-shadow var(--hop-t) var(--hop-wait) infinite;
}
/* Pressed: the face pushes down into its edge and squishes a little, and the hop waits. */
.at-play:active .at-play-face, .at-play.is-down .at-play-face {
  animation: none; translate: 0 6px; scale: 1.05 .95; box-shadow: 0 3px 0 var(--g-deep);
}
.at-play:active .at-play-shadow, .at-play.is-down .at-play-shadow { animation: none; scale: .94 1; }

/* The hop: a crouch, up slowing and down speeding up like a ball, a squash on landing, a small bounce,
   then a rest. Up and down (at-hop) and the squash and stretch (at-squash) run side by side, so each
   keeps its own timing; the ground shadow (at-shadow) shrinks and fades while the button is up. */
@keyframes at-hop {
  0%, 6% { translate: 0 0; animation-timing-function: cubic-bezier(.33, .66, .66, 1); }
  23% { translate: 0 calc(-1 * var(--hop)); animation-timing-function: cubic-bezier(.33, 0, .66, .33); }
  40%, 43% { translate: 0 0; animation-timing-function: cubic-bezier(.33, .66, .66, 1); }
  49% { translate: 0 calc(-.22 * var(--hop)); animation-timing-function: cubic-bezier(.33, 0, .66, .33); }
  55%, 100% { translate: 0 0; }
}
@keyframes at-squash {
  0% { scale: 1 1; animation-timing-function: ease-in-out; }
  6% { scale: 1.08 .9; animation-timing-function: cubic-bezier(.2, .8, .4, 1); }    /* crouch */
  12% { scale: .94 1.07; animation-timing-function: ease-out; }                     /* take-off stretch */
  21% { scale: 1 1; animation-timing-function: ease-in; }
  38% { scale: .96 1.04; animation-timing-function: ease-in; }                      /* falling */
  40.5% { scale: 1.1 .88; animation-timing-function: ease-out; }                     /* landing squash */
  45% { scale: .97 1.03; animation-timing-function: ease-in-out; }
  51% { scale: 1 1; }
  55% { scale: 1.04 .96; animation-timing-function: ease-out; }
  60% { scale: .99 1.01; }
  65%, 100% { scale: 1 1; }
}
@keyframes at-shadow {
  0% { scale: 1 1; opacity: 1; animation-timing-function: ease-in-out; }
  6% { scale: 1.08 1; opacity: 1; animation-timing-function: cubic-bezier(.33, .66, .66, 1); }
  23% { scale: .62 .62; opacity: .4; animation-timing-function: cubic-bezier(.33, 0, .66, .33); }
  40% { scale: 1.12 1; opacity: 1; animation-timing-function: ease-out; }
  43% { scale: 1 1; opacity: 1; animation-timing-function: cubic-bezier(.33, .66, .66, 1); }
  49% { scale: .9 .9; opacity: .8; animation-timing-function: cubic-bezier(.33, 0, .66, .33); }
  55%, 100% { scale: 1 1; opacity: 1; }
}

/* a crew member beside the play button, standing on the arch */
.at-crew {
  position: absolute; z-index: 0; left: max(0px, calc(50% - clamp(100px, 17vh, 132px) / 2 - 172px));
  bottom: calc(-1 * clamp(24px, 6vh, 60px)); width: 160px; height: clamp(190px, 40vh, 360px);
  pointer-events: none;
}
.at-crew img { width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; }
@media (max-width: 380px) { .at-crew { width: 118px; left: -4px; } }

/* ======================================================= the win card */
/* The person and the card sit together in the middle of the screen, with the title screen's burst of
   light behind the person (Phil, Nov 13, 2026: on a tall screen the space above the card read as
   blank). --fig-img is the person's whole height: at most 460px, since the crew art is about 940px
   tall and anything bigger would go soft on a 2x screen. --fig is how much of them shows above the
   card: head to hips (Phil, Nov 13: "can we reveal a bit more"). */
.arcade-win {
  --fig-img: clamp(280px, 56vh, 460px);
  --fig: calc(var(--fig-img) * 0.58);
  position: fixed; inset: 0; z-index: 60; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
/* the board behind, dimmed in the game's own deep color */
.aw-dim { position: absolute; inset: 0; background: rgba(9, 25, 52, .6); background: color-mix(in srgb, var(--g-deep) 82%, transparent); }
.aw-wrap { position: relative; width: min(100%, 380px); margin-top: var(--fig); }
.arcade-win.no-crew .aw-wrap { margin-top: 0; }
.aw-burst {
  position: absolute; left: 50%; top: calc(-0.55 * var(--fig)); width: 240vmax; height: 240vmax;
  transform: translate(-50%, -50%); pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, .34) 0, rgba(255, 255, 255, .12) 9%, rgba(255, 255, 255, 0) 20%),
    repeating-conic-gradient(rgba(255, 255, 255, .14) 0deg 9deg, rgba(255, 255, 255, 0) 9deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, #000 10%, transparent 32%);
  mask-image: radial-gradient(circle, #000 0, #000 10%, transparent 32%);
}
/* The person stands behind the card, so the card hides everything below their waist. Clipped only
   along the card's bottom edge: a flag or pom-poms held overhead still show. */
/* The person is centered by the layout (flex), not by shifting them back half their own width: the
   picture's width is 0 until it loads, and Safari ran the rise from that, so the person came up right
   of center and then jumped into place (Phil, Nov 15, 2026). A picture wider than the box still
   centers, spilling out evenly on both sides. */
.aw-fig {
  position: absolute; left: 50%; bottom: 0; width: 320px; height: calc(100% + var(--fig));
  transform: translateX(-50%); clip-path: inset(-60% -40% 0 -40%); pointer-events: none;
  display: flex; justify-content: center; align-items: flex-start;
}
.aw-fig img {
  flex: none;
  height: calc(var(--fig-img) * var(--reach, 1));
  margin-top: calc(8px - var(--fig-img) * (var(--reach, 1) - 1));
  width: auto; max-width: none;
}
/* Until their picture has loaded, the person waits out of sight, and then rises */
.arcade-win.aw-waiting .aw-fig img { visibility: hidden; animation-play-state: paused; }
.aw-card {
  position: relative; z-index: 1; background: #fff; border-radius: 30px; text-align: center;
  padding: 34px 18px 24px; box-shadow: 0 8px 0 var(--g-deep);
}
.arcade-win.no-crew .aw-card { padding-top: 26px; }
.aw-name {
  position: absolute; left: 50%; top: 0; transform: translate(-50%, -50%);
  background: var(--g-deep); color: #fff; font-weight: 800; font-size: 17px; line-height: 1;
  padding: 8px 16px; border-radius: 999px; white-space: nowrap; box-shadow: 0 0 0 4px #fff;
}
.aw-card h2 { margin: 6px 0 4px; font-weight: 900; font-size: clamp(28px, 5vh, 36px); line-height: 1.1; color: var(--g-deep); }
.aw-stars { display: flex; justify-content: center; gap: 6px; margin: 6px 0 18px; font-size: clamp(40px, 7vh, 54px); }
.aw-stars .as-star:nth-child(2) { transform: translateY(-10px) scale(1.15); }
.aw-stars.aw-pieces { gap: 0; font-size: clamp(56px, 9vh, 72px); margin: 10px 0 18px; }
.aw-btns { display: flex; justify-content: center; gap: 18px; }
.aw-btn {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  background: var(--g-deep); color: #fff; box-shadow: 0 6px 0 rgba(0, 0, 0, .25);
  transition: transform .12s ease;
}
.aw-btn.ghost { background: #fff; color: var(--g-deep); box-shadow: inset 0 0 0 4px var(--g-deep), 0 6px 0 var(--g-deep); }
.aw-btn svg { width: 36px; height: 36px; }
.aw-btn:active { transform: translateY(4px); }

/* the one moment: the stars (or pieces) pop in, the person rises, a little confetti falls once */
.arcade-win .aw-stars :is(.as-star, .as-piece) { animation: as-pop .35s both; }
.arcade-win .aw-stars :is(.as-star, .as-piece):nth-child(1) { animation-delay: .25s; }
.arcade-win .aw-stars :is(.as-star, .as-piece):nth-child(2) { animation-delay: .4s; }
.arcade-win .aw-stars :is(.as-star, .as-piece):nth-child(3) { animation-delay: .55s; }
.arcade-win .aw-fig img { animation: aw-rise .5s .05s cubic-bezier(.3, 1.4, .6, 1) both; }
.aw-confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.aw-confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: aw-fall 1.8s ease-in both; }
@keyframes as-pop { from { opacity: 0; scale: .2; } }
/* the star (or piece) just earned: in last, overshooting, with a glow */
.arcade-win .aw-stars :is(.as-star, .as-piece).as-new { animation: as-pop-new .7s .75s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes as-pop-new {
  0% { opacity: 0; scale: .2; filter: drop-shadow(0 0 0 rgba(255, 220, 90, 0)); }
  60% { opacity: 1; scale: 1.45; filter: drop-shadow(0 0 14px rgba(255, 220, 90, .95)); }
  100% { scale: 1; filter: drop-shadow(0 0 0 rgba(255, 220, 90, 0)); }
}
@keyframes aw-rise { from { translate: 0 40%; } }
@keyframes aw-fall { to { transform: translateY(110vh) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) {
  .arcade-win *, .arcade-title * { animation: none !important; transition: none !important; }
  .aw-confetti { display: none; }
}
