/* ==========================================================================
   Games beside pick-1-of-3 (js/games.js) and the music button (js/music.js).
   Loaded last. Every game draws inside #stage (class "stage game game--X"),
   except the basket, which sits in Zakzak's hands.
   ========================================================================== */

/* ---------- Shared ---------- */
.option.is-lifted { opacity: .25; }
.option.is-gone { visibility: hidden; }
.option.is-over { scale: 1.08; box-shadow: 0 0 0 6px #ffd84d, 0 6px 0 #d8d0f7; }

/* A picture on its way somewhere (dragged, or sent by a tap) */
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  box-sizing: border-box;
  border-radius: 24%;
  background: linear-gradient(#fff 55%, #f2eeff);
  border: 3px solid #fff;
  box-shadow: 0 12px 22px rgba(74, 63, 122, .25);
  pointer-events: none;
  will-change: transform;
}
.drag-ghost img { display: block; width: 100%; height: 100%; }

/* A layer leaving (basket, old bubbles) */
.is-bye { opacity: 0 !important; transition: opacity .4s; }

/* ---------- Basket: in Zakzak's hands ---------- */
.zk-basket {
  position: absolute;
  width: clamp(120px, 36vmin, 190px);
  aspect-ratio: 120 / 70;
  z-index: 1;
  pointer-events: none;
  animation: bs-in .5s cubic-bezier(.3, 1.4, .5, 1);
}
.zk-basket svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.bs-handle { stroke: #a8692f; stroke-width: 7; stroke-linecap: round; }
.bs-hole { fill: #7a4a1f; }
.bs-body { fill: #d99a52; stroke: #a8692f; stroke-width: 3; stroke-linejoin: round; }
.bs-weave { fill: none; stroke: #b97a3a; stroke-width: 2.5; stroke-linecap: round; }
.bs-rim { fill: none; stroke: #f0be7a; stroke-width: 6; stroke-linecap: round; }
.bs-in {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 22%;
  height: 90%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.bs-item {
  width: 38%;
  margin: 0 -5%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .2));
  animation: bs-drop .35s cubic-bezier(.3, 1.5, .5, 1);
}
.bs-item:nth-child(2) { rotate: 8deg; margin-bottom: 6%; }
.bs-item:nth-child(3) { rotate: -8deg; }
.zk-basket.is-catch { animation: bs-catch .35s ease-out; }
@keyframes bs-in { from { scale: .4; opacity: 0; } }
@keyframes bs-drop { from { translate: 0 -40%; scale: 1.2; } }
@keyframes bs-catch { 40% { scale: 1.08 .92; } }

/* Zakzak's guess leans toward his basket (translate adds to the pointing bounce) */
.game--basket .option.is-guess { animation: opt-point 1.2s ease-in-out infinite, bs-lean 1.5s ease-in-out; }
@keyframes bs-lean {
  0%, 100% { translate: 0 0; }
  40%, 60% { translate: var(--dx, 0) var(--dy, 0); }
}

/* ---------- Match: pictures, shadows and the lines between them ---------- */
.stage.game--match {
  flex-direction: column;
  align-items: center;
  gap: clamp(30px, 10vmin, 70px);
}
.mt-row { position: relative; z-index: 1; display: flex; justify-content: center; gap: 3.5vmin; }
.game--match .option { width: clamp(80px, 25vmin, 140px); height: clamp(80px, 25vmin, 140px); }
.mt-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
.mt-line { stroke-width: 8; stroke-linecap: round; }
.mt-line.is-drag  { stroke: var(--zk); }
.mt-line.is-guess { stroke: var(--zk); stroke-width: 10; stroke-dasharray: 1 18; animation: mt-march 1s linear infinite; }
.mt-line.is-done  { stroke: #4cbf5a; }
.mt-line.is-bad   { stroke: #ff8a8a; }
@keyframes mt-march { to { stroke-dashoffset: -38; } }

.option.mt-spot {
  background: rgba(255, 255, 255, .6);
  border: 3px dashed #b9a7ff;
  box-shadow: none;
}
.mt-spot.is-shadow img { filter: brightness(0); opacity: .3; }
.mt-spot.is-faded img { opacity: .3; }
.mt-spot img { transition: opacity .3s, filter .3s; }
.option.mt-spot.is-filled {
  background: linear-gradient(#fff 55%, #f2eeff);
  border: 3px solid #fff;
}
.mt-spot.is-filled img { filter: none; opacity: 1; }
.option.is-sel { translate: 0 -6px; box-shadow: 0 0 0 6px var(--zk), 0 10px 0 #d8d0f7; }
.option.is-ask { box-shadow: 0 0 0 4px #d9cfff, 0 6px 0 #d8d0f7; }
.option.mt-pic.is-done { opacity: .6; box-shadow: 0 0 0 5px #4cbf5a, 0 6px 0 #d8d0f7; }
.stage.is-wait .option.is-done, .stage.is-wait .option.is-filled { opacity: 1; scale: 1; }

@media (orientation: landscape) {
  .stage.game--match { flex-direction: row; gap: clamp(50px, 12vw, 130px); }
  .game--match .mt-row { flex-direction: column; gap: 1.5vmin; }
  .game--match .option { width: clamp(68px, 22vmin, 110px); height: clamp(68px, 22vmin, 110px); }
}

/* ---------- Hide: cups over the pictures ---------- */
.game--hide .option.hd-cup {
  position: relative;
  overflow: visible;
  background: none;
  border-color: transparent;
  box-shadow: none;
}
.hd-cup::before {   /* the cup's shadow on the ground */
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: -4%;
  height: 14%;
  border-radius: 50%;
  background: rgba(74, 63, 122, .18);
}
.hd-cover {
  position: absolute;
  left: -8%;
  right: -8%;
  top: -4%;
  bottom: -4%;
  z-index: 1;
  pointer-events: none;
  transform-origin: 85% 100%;
  transition: translate .4s cubic-bezier(.3, 1.3, .5, 1), rotate .4s ease-out;
}
.hd-cover svg { display: block; width: 100%; height: 100%; overflow: visible; }
.hd-cup.is-open .hd-cover { translate: 0 -74%; rotate: -14deg; }
.hd-cover--0 { --cup: #ff9cc0; --cup-dk: #e0668f; }
.hd-cover--1 { --cup: #7fcfff; --cup-dk: #3b98d6; }
.hd-cover--2 { --cup: #ffd95e; --cup-dk: #d9a614; }
.cup-body { fill: var(--cup); stroke: var(--cup-dk); stroke-width: 3; stroke-linejoin: round; }
.cup-band { fill: #fff; opacity: .55; }
.cup-shine { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; opacity: .75; }
.cup-rim { fill: var(--cup-dk); }
/* Landscape: the cups stand in a column, so a lifted cup tips toward Zakzak instead of up */
@media (orientation: landscape) {
  .hd-cover { transform-origin: 15% 100%; }
  .hd-cup.is-open .hd-cover { translate: -62% -34%; rotate: -28deg; }
}
.hd-cup.is-hint:not(.is-open) .hd-cover { animation: cup-wiggle .5s ease-in-out 3; }
@keyframes cup-wiggle {
  25% { rotate: -6deg; translate: 0 -6%; }
  75% { rotate: 6deg; translate: 0 -6%; }
}

/* ---------- Bubbles and slice: the stage is the whole screen, pictures move over it ---------- */
.stage.game--bubbles, .stage.game--slice {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  display: block;
  overflow: hidden;
  pointer-events: none;
}
.bb { position: absolute; left: 0; top: 0; will-change: transform; transition: opacity .4s; }
.option.bb-ball {
  pointer-events: auto;
  position: relative;
  width: clamp(92px, 27vmin, 150px);
  height: clamp(92px, 27vmin, 150px);
  padding: 19%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .9);
  background:
    radial-gradient(circle at 30% 27%, rgba(255, 255, 255, .95) 0 7%, rgba(255, 255, 255, 0) 8%),
    radial-gradient(circle at 50% 45%, rgba(255, 255, 255, .55) 0 45%, rgba(190, 230, 255, .45) 70%, rgba(160, 145, 255, .55) 100%);
  box-shadow: inset 0 -10px 20px rgba(130, 115, 235, .25), 0 8px 18px rgba(74, 63, 122, .14);
}
.option.bb-ball.is-pop {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.bb-ball.is-pop::before {   /* the bubble bursts */
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 4px solid #fff;
  animation: bb-burst .45s ease-out forwards;
}
@keyframes bb-burst { to { scale: 1.6; opacity: 0; border-width: 1px; } }

/* ---------- Slice: pictures tossed up, a swipe cuts the right one ---------- */
.sl { position: absolute; left: 0; top: 0; will-change: transform; transition: opacity .4s; }
.option.sl-item {
  pointer-events: auto;
  position: relative;
  width: clamp(100px, 29vmin, 160px);
  height: clamp(100px, 29vmin, 160px);
  padding: 9%;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .9) 0 42%, rgba(255, 255, 255, 0) 70%);
  box-shadow: none;
}
.option.sl-item img { filter: drop-shadow(0 4px 3px rgba(74, 63, 122, .25)); }
.option.sl-item.is-guess { box-shadow: 0 0 0 6px var(--zk); }
.option.sl-item.is-wrong { animation: opt-wiggle .5s ease-in-out; }
.option.sl-item.is-wrong::after { rotate: var(--unspin, 0deg); }   /* upright while the picture spins */
.sl-trail { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 2; }
.sl-trail polyline {
  fill: none;
  stroke: #fff;
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .9;
  filter: drop-shadow(0 0 6px #b9a7ff);
}
.sl-cut { position: absolute; left: 0; top: 0; pointer-events: none; }
.sl-half { position: absolute; inset: 0; padding: 9%; animation: sl-half .9s ease-in forwards; }
.sl-half img { display: block; width: 100%; height: 100%; }
@keyframes sl-half {
  to { translate: var(--mx) var(--my); rotate: var(--rot); opacity: 0; }
}
.sl-juice {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px;
  border-radius: 50%;
  animation: sl-splat .6s ease-out forwards;
}
@keyframes sl-splat {
  from { scale: .3; opacity: 1; }
  to { translate: var(--dx) var(--dy); scale: 1; opacity: 0; }
}

/* ---------- Memory: cards that turn ---------- */
.stage.game--memory {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  gap: 3vmin;
}
.game--memory .option.mm-card {
  position: relative;
  width: clamp(76px, 25vmin, 132px);
  height: clamp(76px, 25vmin, 132px);
  padding: 0;
  overflow: visible;
  background: none;
  border-color: transparent;
  box-shadow: none;
  perspective: 600px;
}
.mm-in {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform: rotateY(180deg);
  transform-style: preserve-3d;
  transition: transform .4s ease-in-out;
}
.mm-card.is-up .mm-in { transform: none; }
.mm-face {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 22%;
  border: 3px solid #fff;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.mm-front {
  padding: 15%;
  background: linear-gradient(#fff 55%, #f2eeff);
  box-shadow: 0 6px 0 #d8d0f7, 0 10px 18px rgba(74, 63, 122, .16);
}
.mm-back {
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .3) 0 24%, transparent 25%),
    repeating-linear-gradient(45deg, #ad9bff 0 10px, #9d89f4 10px 20px);
  box-shadow: 0 6px 0 #7f6bd6, 0 10px 18px rgba(74, 63, 122, .16);
}
.mm-back::after {   /* a star (a "?" only puzzles a 2-year-old) */
  content: "";
  position: absolute;
  inset: 27%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.8l2.8 5.8 6.4.8-4.7 4.4 1.2 6.3L12 17l-5.7 3.1 1.2-6.3-4.7-4.4 6.4-.8z' fill='%23fff' stroke='%23fff' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 3px 0 rgba(74, 63, 122, .35));
}
.mm-card.is-right .mm-front { box-shadow: 0 0 0 5px #4cbf5a, 0 6px 0 #d8d0f7; }
.game--memory .option.is-right { box-shadow: none; }

@media (orientation: landscape) {
  .stage.game--memory { grid-template-columns: repeat(2, auto); gap: 1.5vmin 3vmin; }
  .game--memory .option.mm-card { width: clamp(64px, 22vmin, 104px); height: clamp(64px, 22vmin, 104px); }
}

/* ---------- The music button (house only), sized for a small hand, next to the books ---------- */
.music-btn {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: calc(118px + env(safe-area-inset-left, 0px));
  width: 88px;
  height: 88px;
  padding: 14px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: #bdf0cf;
  box-shadow: 0 6px 0 rgba(74, 63, 122, .2);
  z-index: 2;
  transition: scale .12s;
}
.music-btn svg { display: block; width: 100%; height: 100%; overflow: visible; animation: mu-sway 2.4s ease-in-out infinite; transform-origin: 50% 80%; }
.mu-beam { fill: none; stroke: var(--zk-line); stroke-width: 4.5; stroke-linejoin: round; }
.mu-bar { stroke: var(--zk-line); stroke-width: 4.5; }
.mu-head { fill: var(--zk-line); }
.mu-slash { stroke: #ff6b6b; stroke-width: 6.5; stroke-linecap: round; display: none; }
.music-btn::before, .music-btn::after {   /* little notes float up while it plays */
  content: "♪";
  position: absolute;
  top: 6px;
  right: -4px;
  color: var(--zk-line);
  font: 700 20px/1 system-ui, sans-serif;
  opacity: 0;
  pointer-events: none;
  animation: mu-float 2.6s ease-out infinite;
}
.music-btn::after { content: "♫"; right: auto; left: -2px; animation-delay: 1.3s; }
.music-btn.is-off { background: #e7e4ef; }
.music-btn.is-off svg { animation: none; opacity: .55; }
.music-btn.is-off .mu-slash { display: inline; }
.music-btn.is-off::before, .music-btn.is-off::after { display: none; }
.music-btn.is-press { scale: .93; }
.music-btn.is-bump { animation: opt-pop .4s ease-out; }
@media (max-width: 340px) {   /* small phones: room for the stars counter */
  .music-btn { left: calc(112px + env(safe-area-inset-left, 0px)); width: 72px; height: 72px; padding: 11px; top: calc(22px + env(safe-area-inset-top, 0px)); }
}
@keyframes mu-sway { 50% { rotate: 8deg; } }
@keyframes mu-float {
  0% { translate: 0 0; opacity: 0; }
  20% { opacity: .9; }
  100% { translate: 0 -34px; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .music-btn svg, .music-btn::before, .music-btn::after, .mt-line.is-guess { animation: none; }
  .mm-in, .hd-cover { transition-duration: .01s; }
}
