/* Quinn's Quest: the three mini-games (shadow match, photo puzzle, memory pairs).
   The same field journal as the rest of the game: cloth cover, cream paper, washi tape, polaroids,
   tracing paper, pressed leaves and pixel stickers. Colours come from play/style.css where it is loaded,
   with the same values as fallbacks so the games also stand alone. Every selector is .mg-* or #minigame. */

#minigame, .mg {
  --mg-ink: var(--ink, #3a2431); --mg-soft: var(--ink-soft, #6c5462);
  --mg-paper: var(--paper, #fbf3e3); --mg-line: var(--line, rgba(120,160,205,.32));
  --mg-cover: var(--cover, #b4517d); --mg-cover-d: var(--cover-d, #86345c); --mg-cover-l: var(--cover-l, #d27aa0);
  --mg-pink: var(--pink, #f07aa0); --mg-pink-d: var(--pink-d, #c8467a); --mg-pink-l: var(--pink-l, #ffc6d8);
  --mg-mint: var(--mint, #8fdcb8); --mg-mint-d: var(--mint-d, #3f9a6e);
  --mg-lilac: var(--lilac, #d4bdf2); --mg-lilac-d: var(--lilac-d, #9672cf);
  --mg-butter: var(--butter, #ffe28f); --mg-butter-d: var(--butter-d, #e2a93a);
  --mg-sky: var(--sky, #a8dcf0); --mg-kraft: var(--kraft, #d9b384); --mg-kraft-d: var(--kraft-d, #a9794a);
  --mg-hand: var(--hand, ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", system-ui, sans-serif);
  --mg-tex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .30 0 0 0 0 .22 0 0 0 .11 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  --mg-fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .2' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .38 0 0 0 0 .3 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23f)'/%3E%3C/svg%3E");
  --mg-glow: 0 0 0 5px var(--mg-butter), 0 0 26px 8px rgba(255,216,77,.75);
}
.mg { position:fixed; inset:0; z-index:40; display:flex; align-items:center; justify-content:center; overflow:hidden;
  padding:max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 11vh max(16px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 38%, rgba(70,34,56,.25), rgba(28,12,28,.68));
  -webkit-backdrop-filter:blur(3px) saturate(.9); backdrop-filter:blur(3px) saturate(.9);
  color:var(--mg-ink); font:20px/1.35 var(--mg-hand); -webkit-user-select:none; user-select:none; -webkit-touch-callout:none;
  animation:mg-fade .3s ease both; }
.mg *, .mg *::before, .mg *::after { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
.mg [hidden] { display:none !important; }
.mg img { -webkit-user-drag:none; user-select:none; }
.mg.mg-leaving { opacity:0; transition:opacity .25s ease; pointer-events:none; }
@keyframes mg-fade { from { opacity:0; } }

/* fireflies, petals and seeds drifting up past the book */
.mg-air { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
.mg-air i { position:absolute; left:var(--x); bottom:-40px; width:calc(20px * var(--s)); height:calc(20px * var(--s)); background:center/contain no-repeat; image-rendering:pixelated;
  opacity:0; animation:mg-rise var(--t) linear var(--d) infinite; }
.mg-air i.mg-m0 { filter:drop-shadow(0 0 6px rgba(255,236,150,.95)); }
@keyframes mg-rise { 0% { transform:translate(0,0) rotate(0); opacity:0; } 8% { opacity:.85; } 35% { transform:translate(26px,-38vh) rotate(110deg); }
  65% { transform:translate(-14px,-72vh) rotate(230deg); } 90% { opacity:.7; } 100% { transform:translate(18px,-112vh) rotate(360deg); opacity:0; } }

/* ------------------------------------------------------------------ */
/* The book                                                              */
/* ------------------------------------------------------------------ */
.mg-book { --pad:14px; --in:20px; --top:56px; position:relative; width:min(1120px, 100%); height:100%; max-height:860px; border-radius:24px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0 0h8v1H0zM0 4h8v1H0z' fill='rgba(255,255,255,.07)'/%3E%3Cpath d='M0 0v8h1V0zM4 0v8h1V0z' fill='rgba(0,0,0,.07)'/%3E%3C/svg%3E"), linear-gradient(160deg, var(--mg-cover-l), var(--mg-cover) 30%, var(--mg-cover-d));
  box-shadow: 0 2px 0 var(--mg-cover-d), 0 22px 50px rgba(20,8,20,.5), inset 0 0 0 2px rgba(255,255,255,.1);
  animation:mg-open .5s cubic-bezier(.2,1.25,.4,1) both; }
@keyframes mg-open { from { transform:translateY(26px) scale(.94) rotate(-1deg); opacity:0; } }
.mg-book::before { content:''; position:absolute; inset:5px; border-radius:20px; border:2px dashed rgba(255,226,238,.55); pointer-events:none; }
.mg-book::after { content:''; position:absolute; inset:var(--pad); border-radius:10px; pointer-events:none; z-index:0;
  background: var(--mg-tex), var(--mg-fibre), radial-gradient(ellipse at 30% 0%, #fffaf0, transparent 60%), var(--mg-paper);
  box-shadow: 0 2px 0 #e9d7b8, 0 4px 0 #f6ead3, 0 6px 0 #e2cca8, inset 0 0 34px rgba(170,120,70,.16); }
/* a spread: two pages and the shadow of the spine down the middle */
.mg-book.mg-spread::after { background:
  linear-gradient(90deg, transparent calc(50% - 46px), rgba(150,100,60,.08) calc(50% - 18px), rgba(110,70,40,.28) 50%, rgba(150,100,60,.08) calc(50% + 18px), transparent calc(50% + 46px)),
  var(--mg-tex), var(--mg-fibre), radial-gradient(ellipse at 25% 0%, #fffaf0, transparent 60%), var(--mg-paper); }
.mg-k-shadow .mg-book:not(.mg-spread)::after { background:
  linear-gradient(transparent calc(50% + 28px - 2px), rgba(232,98,143,.28) calc(50% + 28px - 2px), rgba(232,98,143,.28) calc(50% + 28px), transparent calc(50% + 28px)),
  var(--mg-tex), var(--mg-fibre), radial-gradient(ellipse at 25% 0%, #fffaf0, transparent 60%), var(--mg-paper); }
.mg-stage { position:absolute; z-index:2; left:calc(var(--pad) + var(--in)); right:calc(var(--pad) + var(--in)); bottom:calc(var(--pad) + var(--in)); top:calc(var(--pad) + var(--top)); }

/* pressed flowers tucked into the page */
.mg-pressed { position:absolute; z-index:1; pointer-events:none; opacity:.8; filter:saturate(.75) drop-shadow(0 2px 1px rgba(90,60,40,.18)); }
.mg-pressed svg { display:block; width:100%; height:100%; image-rendering:pixelated; }
.mg-fern { width:96px; height:96px; right:calc(var(--pad) + 4px); bottom:calc(var(--pad) + 4px); transform:rotate(-8deg); }
.mg-flower { width:54px; height:54px; left:calc(var(--pad) + 86px); top:calc(var(--pad) + 6px); transform:rotate(12deg); animation:mg-sway 5s ease-in-out infinite; }
.mg-flower .mg-tape { width:70%; height:15px; top:42%; left:50%; transform:translateX(-50%) rotate(28deg); }
@keyframes mg-sway { 50% { transform:rotate(4deg); } }

/* washi tape */
.mg-tape { position:absolute; z-index:3; width:42%; max-width:120px; height:22px; top:-11px; left:50%; transform:translateX(-50%) rotate(-3deg); opacity:.93; pointer-events:none;
  -webkit-clip-path:polygon(0 0,3% 18%,0 36%,3% 54%,0 72%,3% 90%,1% 100%,99% 100%,97% 82%,100% 64%,97% 46%,100% 28%,97% 10%,100% 0);
  clip-path:polygon(0 0,3% 18%,0 36%,3% 54%,0 72%,3% 90%,1% 100%,99% 100%,97% 82%,100% 64%,97% 46%,100% 28%,97% 10%,100% 0); }
.mg-t1 { background: repeating-linear-gradient(-45deg, rgba(255,198,216,.92) 0 7px, rgba(240,122,160,.85) 7px 14px); }
.mg-t2 { background: radial-gradient(circle, rgba(255,255,255,.95) 2.5px, transparent 3px) 0 0/12px 12px, rgba(143,220,184,.9); }
.mg-t3 { background: linear-gradient(90deg, rgba(150,114,207,.35) 50%, transparent 0) 0 0/12px 12px, linear-gradient(rgba(150,114,207,.35) 50%, transparent 0) 0 0/12px 12px, rgba(212,189,242,.9); }
.mg-t4 { background: repeating-linear-gradient(90deg, rgba(255,226,143,.95) 0 6px, rgba(255,240,196,.95) 6px 12px); }

/* ------------------------------------------------------------------ */
/* Picture buttons: stitched paper badges (the same family as the game's) */
/* ------------------------------------------------------------------ */
.mg-btn { --c:var(--mg-sky); --d:#4b93c4; --s:78px; position:absolute; z-index:6; width:var(--s); height:var(--s); padding:0; margin:0; border-radius:50%; border:0; cursor:pointer; color:inherit; font:inherit;
  -webkit-appearance:none; appearance:none; touch-action:manipulation;
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,.55), rgba(255,255,255,0) 46%), var(--mg-tex), var(--c);
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.12), inset 0 0 0 3px rgba(255,255,255,.35), 0 6px 0 var(--d), 0 10px 16px rgba(40,20,40,.32);
  display:grid; place-items:center; transition:transform .09s ease, box-shadow .09s ease, filter .2s; }
.mg-btn::before { content:''; position:absolute; inset:7px; border-radius:50%; border:2.5px dashed rgba(255,255,255,.8); pointer-events:none; }
.mg-btn .mg-ico { display:block; width:56%; height:56%; position:relative; z-index:1; image-rendering:pixelated; filter:drop-shadow(0 2px 0 rgba(58,36,49,.18)); }
.mg-btn:active { transform:translateY(5px) scale(.97); box-shadow: inset 0 -2px 0 rgba(0,0,0,.12), inset 0 0 0 3px rgba(255,255,255,.35), 0 1px 0 var(--d), 0 3px 6px rgba(40,20,40,.3); filter:brightness(1.06); }
.mg-back { --c:#fff1dc; --d:var(--mg-kraft-d); top:-12px; left:-12px; }
.mg-back::before { border-color:rgba(169,121,74,.55); }
.mg-say { --c:var(--mg-mint); --d:var(--mg-mint-d); top:-12px; right:-12px; }
.mg-go { --c:var(--mg-pink); --d:var(--mg-pink-d); --s:112px; position:relative; top:auto; left:auto; animation:mg-bob 1.8s ease-in-out infinite; }
.mg-go .mg-ico { width:52%; height:52%; margin-left:7%; }
.mg-go:active { animation:none; }
@keyframes mg-bob { 50% { transform:translateY(-7px); } }

/* the trail of pressed leaves: one for each thing to do, coloured in as she goes */
.mg-trail { position:absolute; z-index:4; top:calc(var(--pad) + 10px); left:50%; transform:translateX(-50%); display:flex; align-items:center; gap:4px; padding:7px 20px; pointer-events:none; }
.mg-trail .mg-tape { inset:9px 0; top:9px; left:0; width:100%; max-width:none; height:auto; transform:rotate(-1.2deg); opacity:.75; }
.mg-trail i { position:relative; z-index:4; width:30px; height:30px; transform:rotate(calc(var(--i) * 37deg - 20deg)); filter:grayscale(1) brightness(1.15) opacity(.6); transition:filter .3s; }
.mg-trail i svg { width:100%; height:100%; display:block; image-rendering:pixelated; }
.mg-trail i.mg-on { filter:none; animation:mg-leaf-on .55s cubic-bezier(.3,1.7,.5,1) both; }
@keyframes mg-leaf-on { 0% { transform:scale(2.2) rotate(-80deg); } 100% { transform:rotate(calc(var(--i) * 37deg - 20deg)); } }

/* ------------------------------------------------------------------ */
/* 1. Shadow match: tracing-paper shadows on one page, polaroids on the other */
/* ------------------------------------------------------------------ */
.mg-k-shadow .mg-stage { display:flex; flex-direction:column; gap:var(--spine, 40px); }
.mg-k-shadow .mg-spread .mg-stage { flex-direction:row; }
.mg-page { position:relative; flex:1 1 0; min-width:0; min-height:0; display:flex; align-items:center; justify-content:center; }
.mg-photos { z-index:2; }
.mg-wrap { width:var(--row); display:flex; flex-wrap:wrap; justify-content:center; align-content:center; gap:var(--gap); }
.mg-slot { position:relative; flex:none; width:var(--cell); height:var(--cell); border-radius:5px; display:grid; place-items:center; cursor:pointer; touch-action:none;
  background: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,.5)), repeating-linear-gradient(90deg, var(--mg-line) 0 1px, transparent 1px 20px), repeating-linear-gradient(var(--mg-line) 0 1px, transparent 1px 20px), #fbf8f0;
  box-shadow: 0 1px 2px rgba(0,0,0,.15), 0 10px 20px rgba(60,30,40,.18); rotate:1.6deg; transition:box-shadow .2s, scale .2s;
  animation:mg-land .55s cubic-bezier(.2,1.3,.4,1) backwards; animation-delay:calc(var(--i) * .09s + .15s); }
.mg-slot:nth-child(even) { rotate:-1.8deg; }
.mg-slot:nth-child(3n) { rotate:.6deg; }
.mg-slot .mg-tape { width:44%; height:20px; top:-10px; }
.mg-sil { display:block; width:80%; height:80%; object-fit:contain; pointer-events:none; opacity:.9;
  filter:brightness(0) invert(14%) sepia(30%) saturate(900%) hue-rotate(280deg); animation:mg-breathe 3.6s ease-in-out infinite; animation-delay:calc(var(--i) * -.9s); transition:all .45s cubic-bezier(.3,1.3,.5,1); }
.mg-sil-dark { width:84%; height:84%; object-fit:cover; border-radius:3px; filter:grayscale(1) brightness(.34) contrast(1.7); }
@keyframes mg-breathe { 50% { transform:translateY(-3px) scale(1.025); opacity:.78; } }
@keyframes mg-land { from { translate:0 -22px; scale:1.05; opacity:0; } }
.mg-slot.mg-over, .mg-slot.mg-sel { box-shadow: var(--mg-glow); scale:1.05; }
.mg-slot.mg-sel .mg-sil { animation:mg-wiggle .9s ease-in-out infinite; }
/* matched: the photograph lies on the tracing paper and its shadow becomes a little sticker */
.mg-slot.mg-done { cursor:default; }
.mg-slot.mg-done .mg-photo { inset:6% 6% 8% 6%; rotate:-2.5deg; z-index:1; cursor:default; animation:none; }
.mg-slot.mg-done .mg-sil { position:absolute; z-index:4; width:44%; height:44%; right:-9%; bottom:-7%; opacity:1; animation:mg-stick .6s .25s cubic-bezier(.3,1.6,.5,1) backwards;
  filter:brightness(0) invert(1) drop-shadow(2px 0 0 #3a2431) drop-shadow(-2px 0 0 #3a2431) drop-shadow(0 2px 0 #3a2431) drop-shadow(0 -2px 0 #3a2431) drop-shadow(0 4px 3px rgba(40,20,30,.35)); }
.mg-slot.mg-done .mg-sil-dark { width:34%; height:34%; border-radius:50%; filter:none; box-shadow:0 0 0 3px #fff, 0 0 0 5px #3a2431; }
.mg-slot.mg-done::after { content:''; position:absolute; inset:-8px; border-radius:10px; pointer-events:none; box-shadow:0 0 0 4px var(--mg-butter); opacity:0; animation:mg-ring .9s ease-out .2s; }
@keyframes mg-stick { from { transform:scale(2.4) rotate(-40deg); opacity:0; } }
@keyframes mg-ring { 0% { opacity:1; transform:scale(.92); } 100% { opacity:0; transform:scale(1.12); } }
@keyframes mg-wiggle { 0%, 100% { transform:rotate(0); } 25% { transform:rotate(-3deg); } 75% { transform:rotate(3deg); } }

.mg-cell { position:relative; flex:none; width:var(--cell); height:var(--cell); }
.mg-cell.mg-empty::before { content:''; position:absolute; inset:9%; border:3px dashed rgba(58,36,49,.16); border-radius:4px; }
.mg-photo { position:absolute; inset:0; padding:6% 6% 15%; border-radius:3px; cursor:grab; touch-action:none; rotate:-2.2deg;
  background: var(--mg-tex), #fffdf8; box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 10px 20px rgba(60,30,40,.26); transition:scale .16s ease, box-shadow .16s ease;
  animation:mg-deal .55s cubic-bezier(.2,1.3,.4,1) backwards; animation-delay:calc(var(--i) * .09s + .3s); }
.mg-cell:nth-child(even) .mg-photo { rotate:2.4deg; }
.mg-cell:nth-child(3n) .mg-photo { rotate:-.8deg; }
.mg-photo img { display:block; width:100%; height:100%; object-fit:cover; pointer-events:none; border-radius:1px; background:#2a2024; }
.mg-photo .mg-tape { width:46%; height:20px; top:-10px; }
.mg-photo.mg-lift { z-index:20; scale:1.08; cursor:grabbing; box-shadow: 0 2px 3px rgba(0,0,0,.2), 0 24px 34px rgba(40,20,30,.38); transition:scale .16s ease, box-shadow .16s ease; }
.mg-photo.mg-sel { scale:1.05; box-shadow: var(--mg-glow); animation:mg-hop 1s ease-in-out infinite; }
@keyframes mg-deal { from { translate:0 -34px; scale:.9; opacity:0; } }
@keyframes mg-hop { 50% { translate:0 -6px; } }

/* ------------------------------------------------------------------ */
/* 2. Photo puzzle: a polaroid frame with a faint guide, pieces spilled in a pocket */
/* ------------------------------------------------------------------ */
.mg-tray { position:absolute; border-radius:22px; pointer-events:none;
  background: radial-gradient(circle, rgba(169,121,74,.22) 1.2px, transparent 1.8px) 0 0/16px 16px, rgba(217,179,132,.12);
  box-shadow: inset 0 0 0 3px rgba(169,121,74,.16); }
.mg-tray::before { content:''; position:absolute; inset:7px; border-radius:16px; border:2.5px dashed rgba(169,121,74,.32); }
.mg-frame { position:absolute; margin:0; padding:var(--fp) var(--fp) var(--fb); border-radius:3px;
  background: var(--mg-tex), #fffdf8; box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 14px 26px rgba(60,30,40,.26);
  animation:mg-fadein .4s ease backwards; }
@keyframes mg-fadein { from { opacity:0; } }
.mg-frame .mg-tape { top:-11px; left:14%; width:28%; transform:rotate(-12deg); }
.mg-frame .mg-tape.mg-tr { left:auto; right:-5%; top:9%; width:24%; transform:rotate(40deg); }
.mg-board { position:relative; width:100%; height:100%; overflow:hidden; border-radius:1px; background:#ead9c0; box-shadow:inset 0 0 0 1px rgba(58,36,49,.12); }
.mg-guide, .mg-whole { position:absolute; inset:0; background:center/100% 100% no-repeat; }
.mg-guide { opacity:.3; filter:grayscale(.5) sepia(.55) contrast(.85); }
.mg-whole { opacity:0; transition:opacity .9s ease .25s; }
.mg-lines { position:absolute; inset:0; width:100%; height:100%; overflow:visible; }
.mg-lines path { fill:none; stroke:rgba(58,36,49,.32); stroke-width:1.6; stroke-dasharray:5 5; stroke-linecap:round; animation:mg-march 1.6s linear infinite; }
@keyframes mg-march { to { stroke-dashoffset:-20; } }
.mg-credit { position:absolute; left:var(--fp); right:var(--fp); bottom:0; height:var(--fb); display:flex; align-items:center; justify-content:center; margin:0;
  font-size:12px; line-height:1.15; font-weight:600; color:#5b4a54; text-align:center; overflow:hidden; overflow-wrap:anywhere; opacity:0; transition:opacity .6s ease .6s; }
.mg-pc { position:absolute; left:0; top:0; z-index:3; pointer-events:none; transform-origin:50% 50%; transition:scale .15s ease, filter .2s ease;
  filter: drop-shadow(0 1px 0 rgba(58,36,49,.35)) drop-shadow(0 5px 4px rgba(40,20,30,.32)); }
.mg-pc-img { position:absolute; inset:0; pointer-events:auto; touch-action:none; cursor:grab; background-repeat:no-repeat; }
.mg-pc-edge { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; overflow:visible; }
.mg-pc-edge path { fill:none; vector-effect:non-scaling-stroke; }
.mg-e1 { stroke:rgba(255,255,255,.7); stroke-width:2.5; }
.mg-e2 { stroke:rgba(58,36,49,.42); stroke-width:1; }
.mg-pc.mg-held { scale:1.07; filter: drop-shadow(0 1px 0 rgba(58,36,49,.35)) drop-shadow(0 16px 12px rgba(40,20,30,.38)); }
.mg-pc.mg-held .mg-pc-img { cursor:grabbing; }
.mg-pc.mg-sel { scale:1.06; filter: drop-shadow(0 0 3px #ffe28f) drop-shadow(0 0 10px rgba(255,216,77,.95)) drop-shadow(0 8px 8px rgba(40,20,30,.3)); }
.mg-pc.mg-sel .mg-e1 { stroke:var(--mg-butter); stroke-width:4; }
.mg-pc.mg-set { z-index:1 !important; filter:none; }
.mg-pc.mg-set .mg-pc-img { cursor:default; }
.mg-pc.mg-set .mg-e1 { stroke:rgba(255,255,255,.22); stroke-width:1.2; }
.mg-pc.mg-set .mg-e2 { stroke:rgba(58,36,49,.12); }
.mg-pc.mg-intro { filter:none; }
.mg-pc.mg-intro .mg-e1, .mg-pc.mg-intro .mg-e2 { stroke:transparent; }
.mg-solved .mg-whole { opacity:1; }
.mg-solved .mg-pc { opacity:0; transition:opacity .5s ease 1s; }
.mg-solved .mg-pc-img { pointer-events:none; }
.mg-solved .mg-lines { opacity:0; transition:opacity .4s; }
.mg-solved .mg-credit { opacity:1; }
.mg-solved .mg-frame { animation:mg-proud 1s cubic-bezier(.3,1.4,.5,1) .2s; }
@keyframes mg-proud { 40% { transform:scale(1.03) rotate(-1deg); } }

/* ------------------------------------------------------------------ */
/* 3. Memory pairs: gingham-backed cards with a magnifying glass, photographs on the front */
/* ------------------------------------------------------------------ */
.mg-k-pairs .mg-stage { display:flex; align-items:center; justify-content:center; }
.mg-deck { width:var(--row); display:flex; flex-wrap:wrap; justify-content:center; align-content:center; gap:var(--gap); }
.mg-card { position:relative; flex:none; width:var(--cell); height:calc(var(--cell) * 1.1); padding:0; margin:0; border:0; background:none; cursor:pointer; perspective:900px; color:inherit; font:inherit;
  -webkit-appearance:none; appearance:none; touch-action:manipulation; animation:mg-deal .5s cubic-bezier(.2,1.3,.4,1) backwards; animation-delay:calc(var(--i) * .05s + .15s); }
.mg-card-in { position:absolute; inset:0; transform-style:preserve-3d; transition:transform .55s cubic-bezier(.3,1.35,.5,1); }
.mg-card.mg-up .mg-card-in { transform:rotateY(180deg); }
.mg-card:active:not(.mg-up) .mg-card-in { transform:scale(.96); }
.mg-cardback, .mg-cardface { position:absolute; inset:0; border-radius:10px; -webkit-backface-visibility:hidden; backface-visibility:hidden; overflow:hidden; }
.mg-cardback { display:grid; place-items:center;
  background: linear-gradient(90deg, rgba(150,114,207,.32) 50%, transparent 0) 0 0/18px 18px, linear-gradient(rgba(150,114,207,.32) 50%, transparent 0) 0 0/18px 18px, var(--mg-tex), #e7d8f8;
  box-shadow: inset 0 0 0 4px #fffdf8, inset 0 0 0 6px rgba(150,114,207,.5), 0 1px 2px rgba(0,0,0,.2), 0 8px 16px rgba(60,30,40,.25); }
.mg-cardback::before { content:''; position:absolute; inset:11px; border-radius:6px; border:2.5px dashed rgba(255,255,255,.85); }
.mg-cardback::after { content:''; position:absolute; inset:0; background:linear-gradient(115deg, transparent 35%, rgba(255,255,255,.55) 48%, transparent 60%) no-repeat;
  background-size:250% 100%; background-position:120% 0; animation:mg-shine 6s ease-in-out infinite; animation-delay:calc(var(--i) * .35s); }
@keyframes mg-shine { 0%, 70% { background-position:120% 0; } 100% { background-position:-120% 0; } }
.mg-cardback .mg-mag { position:relative; width:54%; height:auto; aspect-ratio:1; padding:9%; border-radius:50%; image-rendering:pixelated;
  background: var(--mg-tex), #fffdf8; box-shadow: 0 0 0 3px rgba(150,114,207,.55), 0 3px 0 rgba(150,114,207,.35); }
.mg-cardface { transform:rotateY(180deg); padding:7% 7% 7%; background: var(--mg-tex), #fffdf8; box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 8px 16px rgba(60,30,40,.25); }
.mg-cardface img { display:block; width:100%; height:100%; object-fit:cover; pointer-events:none; border-radius:3px; background:#2a2024; }
.mg-card.mg-got { cursor:default; }
.mg-card.mg-got .mg-cardface { box-shadow: 0 0 0 4px var(--mg-butter), 0 0 20px 5px rgba(255,216,77,.55), 0 8px 16px rgba(60,30,40,.25); }
.mg-card.mg-got .mg-cardface::after { content:''; position:absolute; right:3%; top:3%; width:26%; height:26%; background:center/contain no-repeat; image-rendering:pixelated;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath fill='%233a2431' d='M1 0h2v1H1zM4 0h2v1H4zM0 1h1v2H0zM3 1h1v1H3zM6 1h1v2H6zM1 3h1v1H1zM5 3h1v1H5zM2 4h1v1H2zM4 4h1v1H4zM3 5h1v1H3z'/%3E%3Cpath fill='%23f07aa0' d='M1 1h2v2H1zM4 1h2v2H4zM3 2h1v1H3zM2 3h3v1H2zM3 4h1v1H3z'/%3E%3Cpath fill='%23ffc6d8' d='M1 1h1v1H1zM4 1h1v1H4z'/%3E%3C/svg%3E");
  animation:mg-stick .5s cubic-bezier(.3,1.6,.5,1) .3s backwards; filter:drop-shadow(0 2px 1px rgba(40,20,30,.3)); }
.mg-card.mg-got .mg-card-in { animation:mg-jump .55s cubic-bezier(.3,1.5,.5,1); }
@keyframes mg-jump { 40% { translate:0 -10px; } }

/* ------------------------------------------------------------------ */
/* The reward: a kraft tag with gems popping into their sockets, and a button to go on */
/* ------------------------------------------------------------------ */
.mg-reward { position:absolute; inset:0; z-index:30; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:22px; pointer-events:none; }
.mg-reward:not(.mg-in-tray)::before { content:''; position:absolute; inset:-8px; border-radius:16px; background:radial-gradient(ellipse at 50% 50%, rgba(253,247,234,.97) 20%, rgba(251,243,227,.86) 60%, rgba(251,243,227,.7)); animation:mg-fadein .5s ease backwards; }
.mg-reward > * { position:relative; pointer-events:auto; }
.mg-tag { padding:22px 26px 20px 40px; border-radius:10px 22px 22px 10px;
  background: var(--mg-tex), linear-gradient(170deg, #e8c99c, var(--mg-kraft) 60%, #cfa26f);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.25), 0 3px 0 var(--mg-kraft-d), 0 16px 28px rgba(60,30,20,.35);
  transform:rotate(-2deg); animation:mg-drop .7s cubic-bezier(.2,1.35,.4,1) backwards; }
.mg-tag::before { content:''; position:absolute; left:13px; top:50%; width:16px; height:16px; margin-top:-8px; border-radius:50%; background:#fff8ea; box-shadow:inset 0 2px 2px rgba(0,0,0,.25), 0 0 0 3px #e2a93a; }
.mg-tag::after { content:''; position:absolute; inset:7px 7px 7px 34px; border-radius:6px 16px 16px 6px; border:2px dashed rgba(255,255,255,.6); pointer-events:none; }
.mg-tag .mg-tape { width:34%; top:-12px; left:30%; transform:rotate(-8deg); }
.mg-tag .mg-tape.mg-t2 { left:-4%; top:auto; bottom:-10px; transform:rotate(-24deg); width:26%; max-width:70px; }
@keyframes mg-drop { from { transform:translateY(-60px) rotate(-14deg) scale(.8); opacity:0; } }
.mg-gems { position:relative; z-index:1; display:flex; gap:12px; }
.mg-gem { position:relative; width:64px; height:57px; }
.mg-gem svg { position:absolute; inset:0; width:100%; height:100%; image-rendering:pixelated; }
.mg-gem-art { animation:mg-pop .55s cubic-bezier(.3,1.7,.5,1) backwards; animation-delay:calc(.7s + var(--i) * .38s); filter:drop-shadow(0 3px 0 rgba(42,42,106,.35)); }
.mg-gem::after { content:''; position:absolute; right:-6px; top:-8px; width:22px; height:22px; background:center/contain no-repeat; image-rendering:pixelated; opacity:0;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath fill='%23fff' d='M3 0h1v2H3zM0 3h2v1H0zM5 3h2v1H5zM3 5h1v2H3z'/%3E%3Cpath fill='%23ffe28f' d='M2 2h3v3H2z'/%3E%3Cpath fill='%23fff' d='M3 3h1v1H3z'/%3E%3C/svg%3E");
  animation:mg-twinkle 1.8s ease-in-out infinite; animation-delay:calc(1.1s + var(--i) * .38s); }
@keyframes mg-pop { 0% { transform:translateY(-70px) scale(.2) rotate(-60deg); opacity:0; } 60% { transform:translateY(4px) scale(1.18) rotate(6deg); opacity:1; } 100% { transform:none; } }
@keyframes mg-twinkle { 0%, 100% { opacity:0; transform:scale(.4) rotate(0); } 40% { opacity:1; transform:scale(1) rotate(45deg); } 70% { opacity:0; } }

/* ------------------------------------------------------------------ */
/* The demonstration hand, ghosts it carries, and the celebration bits    */
/* ------------------------------------------------------------------ */
.mg-fx { position:absolute; inset:0; pointer-events:none; z-index:20; overflow:hidden; }
.mg-hand { position:fixed; left:0; top:0; z-index:50; width:80px; pointer-events:none; filter:drop-shadow(0 8px 6px rgba(20,8,20,.4)); }
.mg-hand .mg-hand-art { display:block; width:100%; height:auto; image-rendering:pixelated; transform-origin:32% 4%; transition:transform .12s ease; }
.mg-hand.mg-press .mg-hand-art { transform:scale(.86) translateY(3px); }
.mg-tap { position:absolute; left:32%; top:3%; width:56px; height:56px; margin:-28px 0 0 -28px; border-radius:50%; border:5px solid rgba(255,255,255,.95); opacity:0; }
.mg-hand.mg-press .mg-tap { animation:mg-tapring .6s ease-out; }
@keyframes mg-tapring { from { transform:scale(.3); opacity:1; } to { transform:scale(1.4); opacity:0; } }
.mg-ghost { position:fixed; z-index:45; pointer-events:none; transition:opacity .25s ease; }
.mg-ghost, .mg-ghost * { pointer-events:none !important; animation:none !important; }
.mg-ghost.mg-ghost-out { opacity:0 !important; }
.mg-ghost .mg-photo { box-shadow: 0 2px 3px rgba(0,0,0,.2), 0 24px 34px rgba(40,20,30,.38); }
.mg-ghost .mg-pc { filter: drop-shadow(0 16px 12px rgba(40,20,30,.38)); }
.mg-bit { position:fixed; width:18px; height:18px; margin:-9px 0 0 -9px; background:center/contain no-repeat; image-rendering:pixelated; animation:mg-fly 1.4s cubic-bezier(.15,.7,.35,1) both; }
@keyframes mg-fly { 0% { transform:translate(0,0) scale(.3) rotate(0); opacity:1; } 70% { opacity:1; } 100% { transform:translate(var(--dx), calc(var(--dy) + 80px)) scale(var(--z)) rotate(var(--r)); opacity:0; } }

/* ------------------------------------------------------------------ */
/* Sizes                                                                 */
/* ------------------------------------------------------------------ */
/* phones upright */
@media (orientation:portrait) and (max-width:560px) {
  .mg { padding:max(14px, env(safe-area-inset-top)) 10px 11vh; }
  .mg-book { --pad:10px; --in:12px; --top:52px; border-radius:18px; }
  .mg-btn { --s:68px; }
  .mg-back { top:-8px; left:-8px; } .mg-say { top:-8px; right:-8px; }
  .mg-go { --s:100px; }
  .mg-trail { top:calc(var(--pad) + 8px); padding:6px 12px; gap:2px; }
  .mg-trail i { width:24px; height:24px; }
  .mg-flower { display:none; }
  .mg-fern { width:64px; height:64px; }
  .mg-gem { width:52px; height:46px; } .mg-gems { gap:8px; }
  .mg-tag { padding:18px 18px 16px 34px; }
}
/* short, wide screens (phones sideways): the two buttons move out to the sides of the book */
@media (max-height:500px) {
  .mg { padding:12px max(92px, calc(env(safe-area-inset-right) + 84px)) 10vh max(92px, calc(env(safe-area-inset-left) + 84px)); }
  .mg-book { --pad:9px; --in:11px; --top:20px; border-radius:16px; }
  .mg-book::before { inset:4px; border-radius:13px; }
  .mg-btn { --s:68px; }
  .mg-btn::before { inset:5px; border-width:2px; }
  .mg-back { top:0; left:-84px; } .mg-say { top:0; right:-84px; }
  .mg-go { --s:84px; }
  .mg-trail { top:-9px; padding:4px 12px; gap:1px; }
  .mg-trail i { width:20px; height:20px; }
  .mg-flower { display:none; }
  .mg-fern { width:60px; height:60px; }
  .mg-gem { width:46px; height:41px; } .mg-gems { gap:7px; }
  .mg-tag { padding:14px 16px 12px 32px; }
  .mg-reward { gap:12px; }
  .mg-tape { height:18px; top:-9px; }
  .mg-credit { font-size:10.5px; }
}
@media (max-width:560px) {
  .mg-credit { font-size:10px; }
}

/* Less motion: everything holds still; the games work the same */
.mg.mg-still *, .mg.mg-still *::before, .mg.mg-still *::after { animation:none !important; transition:none !important; }
.mg.mg-still { animation:none; }
.mg.mg-still .mg-air { display:none; }
@media (prefers-reduced-motion:reduce) {
  .mg *, .mg *::before, .mg *::after { animation:none !important; transition:none !important; }
  .mg { animation:none; }
  .mg-air { display:none; }
}

.mg-credit[hidden] { display:none !important; }
