/* Fit complete rows when every card can retain a 44px target and its original proportions. */
body[data-kd-game="memory"] .board.memory-board-fitted{grid-template-columns:repeat(var(--cols),var(--fit-card-width));justify-content:center;align-content:center;scrollbar-gutter:auto;overflow-y:hidden}
body[data-kd-game="memory"] .board.memory-board-fitted .card{width:var(--fit-card-width);height:var(--fit-card-height);min-height:24px;max-height:none;justify-self:center}

/* Accessibility: enlarged text gets natural document flow, including the controls
   normally fixed to a corner. Never make cards or text smaller to force a fit. */
html.memory-large-text{height:auto;overflow:auto}
html.memory-large-text body[data-kd-game="memory"]{height:auto;min-height:100dvh;overflow:visible;display:flex;padding:8px max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left))}
html.memory-large-text body[data-kd-game="memory"]>main{flex:none;min-height:0;padding:0}
html.memory-large-text body[data-kd-game="memory"] .topbar,
html.memory-large-text body[data-kd-game="memory"] .chapter{position:static;width:100%;max-width:100%;margin:8px auto;padding:0}
html.memory-large-text body[data-kd-game="memory"] .topbar,
html.memory-large-text body[data-kd-game="memory"] .toolbar{flex-wrap:wrap;justify-content:center}
html.memory-large-text body[data-kd-game="memory"] .play-area{display:block;flex:none;padding:0}
html.memory-large-text body[data-kd-game="memory"] .game-panel{height:auto;padding:10px;min-width:0}
html.memory-large-text body[data-kd-game="memory"] .game-top,
html.memory-large-text body[data-kd-game="memory"] .stats{flex-wrap:wrap;justify-content:center;gap:12px}
html.memory-large-text body[data-kd-game="memory"] .stats>span{flex-wrap:wrap;justify-content:center}
html.memory-large-text body[data-kd-game="memory"] .level-pill{display:inline-block;white-space:normal}
html.memory-large-text body[data-kd-game="memory"] .board{flex:none;height:auto;max-height:none;overflow:visible;grid-auto-rows:auto}
html.memory-large-text body[data-kd-game="memory"] .card{height:calc(100px + 4em);min-height:180px;max-height:none;aspect-ratio:auto;width:100%}
html.memory-large-text body[data-kd-game="memory"] .board-footer{flex-wrap:wrap;gap:12px;justify-content:center}
html.memory-large-text body[data-kd-game="memory"] .board-footer .text-button{flex:0 0 100%;width:100%;max-width:100%;min-width:0;justify-content:center;overflow-wrap:anywhere}
html.memory-large-text body[data-kd-game="memory"] .memory-reaction-line{position:static;width:100%;max-height:none;overflow:visible;flex-wrap:wrap;justify-content:center}
html.memory-large-text body[data-kd-game="memory"] #feedback{width:100%;max-width:100%;text-align:center}
html.memory-large-text body[data-kd-game="memory"] #levelsButton{width:auto;min-width:44px;padding:8px}
html.memory-large-text body[data-kd-game="memory"] #age3-change,
html.memory-large-text body[data-kd-game="memory"]>.kd-language-switch{position:static;width:auto;max-width:100%;align-self:center;margin:8px;white-space:normal}
html.memory-large-text body[data-kd-game="memory"] dialog{max-width:calc(100% - 16px);overflow-wrap:anywhere}

/* Meeting correction: complete equal rows in the available area. */
body[data-kd-game="memory"] .board.memory-board-fitted{column-gap:var(--fit-gap-x,9px);row-gap:var(--fit-gap-y,9px)}
body[data-kd-game="memory"] .memory-board-compact .card-front{padding:3px;gap:0}
body[data-kd-game="memory"] .memory-board-compact .card-front small{display:none}
body[data-kd-game="memory"] .memory-board-compact .card-face{border-radius:8px}
body[data-kd-game="memory"] .memory-board-compact .card-back:before{inset:3px}
body[data-kd-game="memory"] .memory-board-compact .card-brand-name{display:none}
body[data-kd-game="memory"] .memory-board-compact .card-brand-art{width:90%;height:90%}

/* The fitted gaps must win over the existing landscape layout. */
html:not(.memory-large-text) body[data-kd-game="memory"] .board.memory-board-fitted{column-gap:var(--fit-gap-x,9px);row-gap:var(--fit-gap-y,9px)}
@media(max-width:680px) and (min-height:461px) and (max-height:720px){
 html:not(.memory-large-text) body[data-kd-game="memory"] .board-footer{display:flex;flex-wrap:nowrap;gap:4px}
 html:not(.memory-large-text) body[data-kd-game="memory"] .memory-reaction-line{flex:none;position:static}
 html:not(.memory-large-text) body[data-kd-game="memory"] #memoryReactionActors{height:34px;gap:2px}
 html:not(.memory-large-text) body[data-kd-game="memory"] #memoryReactionActors .memory-actor-portrait{width:32px;height:32px;border-radius:10px}
 html:not(.memory-large-text) body[data-kd-game="memory"] .board-footer>button{flex:1;min-width:0}
}

body[data-kd-game="memory"] .game-top{flex-wrap:wrap;row-gap:2px}body[data-kd-game="memory"] .game-top .active-time{font-size:11px!important;margin-left:auto}#memory-result-time{font-variant-numeric:tabular-nums}
@media(max-height:460px){body[data-kd-game="memory"] .game-top{flex-wrap:nowrap}.game-top .active-time{font-size:10px!important}}

body[data-kd-game="memory"] .play-area{min-width:0}
/* TABLE-AGE3-R93: the full board owns the play area in every orientation. */
@media(max-height:760px),(max-width:680px){
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"]{padding:4px max(4px,env(safe-area-inset-right)) max(52px,env(safe-area-inset-bottom)) max(4px,env(safe-area-inset-left));height:100dvh}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .topbar{position:static;flex-direction:row;width:100%;padding:0 4px;min-height:44px;gap:4px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .brand-wrap{min-width:0;flex:1}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .kd-brand>.kd-logo{width:90px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .memory-brand-duo{display:none}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .chapter{display:none}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .companion{display:none}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"]>main{display:flex;flex:1;min-height:0;padding:0}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .play-area{display:block;flex:1;min-height:0;padding:0 4px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .game-panel{padding:5px;height:100%;min-height:0}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .game-top{flex-wrap:wrap;gap:2px 8px;min-height:24px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .game-top .stats{gap:6px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .game-top .stats>span{font-size:11px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .game-top .stats strong{font-size:14px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .level-pill{font-size:11px;padding:3px 5px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .progress{margin:3px 0;height:3px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .board{max-height:none;min-height:0;flex:1;padding:3px;overflow:hidden;scrollbar-gutter:auto}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .board.memory-board-fitted .card{min-width:0;min-height:0;max-height:none;aspect-ratio:auto}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .board-footer{margin-top:2px;min-height:44px;gap:3px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] .memory-reaction-line{position:static;width:auto;max-height:44px;overflow:hidden}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] #memoryReactionActors{height:36px}
 html:not(.memory-large-text):not(.memory-save-warning) body[data-kd-game="memory"] #age3-change{left:auto;right:8px;bottom:4px;width:auto;max-width:150px}
}
