/* v128 toddler QA: preserve the real proportions of 2–20 handpainted memory cards */
#app .memory127-page.memory127-game .memory127-grid{
 flex:0 1 auto!important;
 width:min(94%,440px)!important;
 height:min(75%,615px)!important;
 max-width:100%!important;
 max-height:calc(100% - 115px)!important;
 min-height:0!important;align-self:center!important;
 justify-items:stretch!important;align-items:stretch!important;
 display:grid!important;grid-template-columns:repeat(4,minmax(0,1fr))!important;
 grid-template-rows:repeat(5,minmax(0,1fr))!important;
 padding:3px!important;gap:clamp(4px,1.4vw,10px)!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(2):last-child){
 grid-template-columns:repeat(2,minmax(0,1fr))!important;
 grid-template-rows:1fr!important;
 width:min(70%,254px)!important;height:clamp(155px,30vh,245px)!important;
 flex:0 0 auto!important;max-height:36%!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(4):last-child){
 grid-template-columns:repeat(2,minmax(0,1fr))!important;
 grid-template-rows:repeat(2,minmax(0,1fr))!important;
 width:min(80%,285px)!important;height:clamp(240px,47vh,370px)!important;
 flex:0 0 auto!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(6):last-child){
 grid-template-columns:repeat(3,minmax(0,1fr))!important;
 grid-template-rows:repeat(2,minmax(0,1fr))!important;
 width:min(90%,350px)!important;height:clamp(205px,43vh,320px)!important;
 flex:0 0 auto!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(8):last-child){
 grid-template-columns:repeat(4,minmax(0,1fr))!important;grid-template-rows:repeat(2,minmax(0,1fr))!important;
 width:min(95%,420px)!important;height:clamp(200px,41vh,300px)!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(10):last-child),
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(12):last-child){
 grid-template-columns:repeat(4,minmax(0,1fr))!important;grid-template-rows:repeat(3,minmax(0,1fr))!important;
 width:min(95%,420px)!important;height:min(62%,430px)!important;
}
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(14):last-child),
#app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(16):last-child){
 grid-template-columns:repeat(4,minmax(0,1fr))!important;grid-template-rows:repeat(4,minmax(0,1fr))!important;
 width:min(95%,420px)!important;height:min(68%,530px)!important;
}
#app .memory127-page .memory127-grid .memory127-card{
 overflow:visible!important;width:100%!important;height:100%!important;
 min-width:0!important;min-height:0!important;
}
#app .memory127-page .memory127-card .memory127-inner{width:100%!important;height:100%!important}
#app .memory127-page .memory127-back,
#app .memory127-page .memory127-front{
 border-radius:clamp(9px,2vw,18px)!important;overflow:hidden!important;
 border:0!important;background:none!important;
 box-shadow:0 2px 3px #70503877!important;
}
#app .memory127-page .memory127-back img{
 width:100%!important;height:100%!important;max-width:100%!important;max-height:100%!important;
 object-fit:contain!important;
}
#app .memory127-page .memory127-front{
 background:url('/memory-v127/card-cream.webp') center/100% 100% no-repeat!important;
}
#app .memory127-page .memory127-front-face{
 width:84%!important;height:78%!important;max-width:84%!important;max-height:78%!important;
 display:grid!important;place-items:center!important;
}
#app .memory127-page .memory127-front-face img{
 width:100%!important;height:100%!important;max-width:100%!important;max-height:100%!important;
 object-fit:contain!important;
}
#app .memory127-page .memory127-controls{
 flex:0 0 auto!important;min-height:45px!important;margin-top:0!important;
}
#app .memory127-page .memory127-choices img{
 object-fit:contain!important;
}
@media(orientation:portrait) and (max-height:630px){
 #app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(2):last-child){height:135px!important}
 #app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(4):last-child){height:220px!important}
 #app .memory127-page .memory127-grid{max-height:calc(100% - 90px)!important}
}
@media(orientation:landscape){
 #app .memory127-page.memory127-game .memory127-grid{
  grid-area:1/2/4/3!important;width:min(100%,580px)!important;
  max-width:100%!important;height:96%!important;max-height:96%!important;
  align-self:center!important;
  grid-template-columns:repeat(5,minmax(0,1fr))!important;
  grid-template-rows:repeat(4,minmax(0,1fr))!important;
 }
 #app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(2):last-child){
  width:min(41%,260px)!important;height:75%!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;grid-template-rows:1fr!important;
 }
 #app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(4):last-child){
  width:min(56%,330px)!important;height:92%!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;grid-template-rows:repeat(2,minmax(0,1fr))!important;
 }
 #app .memory127-page .memory127-grid:has(>.memory127-card:nth-child(6):last-child){
  width:min(70%,390px)!important;height:85%!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;grid-template-rows:repeat(2,minmax(0,1fr))!important;
 }
}

/* Landscape 20-card rounds: no horizontal stretching and no cut-off at bottom */
@media (orientation:landscape){
 #app .memory127-page.memory127-game .memory127-grid:has(>.memory127-card:nth-child(20):last-child),
 #app .memory127-page.memory127-game .memory127-grid:has(>.memory127-card:nth-child(18):last-child){
   width:min(calc(100dvh * .76),510px)!important;
   height:83%!important;
   max-height:83%!important;
   grid-template-columns:repeat(5,minmax(0,1fr))!important;
   grid-template-rows:repeat(4,minmax(0,1fr))!important;
   align-self:center!important;
   margin:0 auto!important;
 }
}
