/* Memory tools stay above the cards. Peeking fits the same ordered board into
   the viewport; the measured placeholder preserves the child's scroll position. */
.memory-play { position: relative; }
.memory-tools {
  position: sticky;
  top: var(--game-settings-space, 84px);
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 76px;
  padding: 10px 14px;
  margin-bottom: 10px;
  border: 2px solid #d4e5cf;
  border-radius: 21px;
  background: #fffdf3;
  box-shadow: 0 3px 0 #9bb98e22;
}
.memory-instruction-copy { min-width: 0; }
.memory-tools .activity-instruction {
  margin: 0;
  padding: 0;
  font-size: 19px;
  line-height: 1.45;
  text-align: left;
  word-break: keep-all;
}
.memory-instruction-copy small {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.4;
  color: #698169;
}
.memory-tools .memory-actions { flex: none; flex-wrap: nowrap; margin: 0; gap: 9px; }
.memory-shell .memory-tools .game-action { width: 50px; height: 50px; min-height: 50px; padding: 8px; }
.memory-tools .game-action .game-action-icon { width: 29px; height: 30px; }
.memory-board { --memory-columns: 5; grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr)); }
.memory-board.count-60 { --memory-columns: 6; grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr)); }
.memory-shell .memory-card { min-width: 44px; min-height: 44px; }

/* These cards are disabled during the existing peek timer: smaller read-only
   preview cells never replace the 44px playable touch targets. */
.is-memory-preview > .memory-play-panel {
  position: fixed;
  z-index: 20;
  inset: var(--game-settings-space, 84px) 12px max(10px, env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 900px);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  padding: 10px;
  border: 2px solid #c6dcb6;
  border-radius: 24px;
  background: #fffdf3;
  box-shadow: 0 8px 32px #33564c33, 0 0 0 100vmax #e0f1eae8;
}
.is-memory-preview .memory-tools { position: static; flex: none; margin-bottom: 8px; padding: 5px 6px 10px; border: 0; border-radius: 0; box-shadow: none; }
.is-memory-preview .memory-board {
  flex: 1;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
  align-items: stretch;
  align-content: stretch;
  gap: 5px;
  padding: 7px;
  border-radius: 17px;
}
.memory-shell .is-memory-preview .memory-card {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 12px 3px 2px;
  border-radius: 9px;
  border-bottom-width: 2px;
  cursor: default;
}
.is-memory-preview .memory-card svg { max-height: 100%; min-height: 0; width: 100%; height: 100%; }
.is-memory-preview .memory-card-number { top: 1px; left: 4px; font-size: 10px; }
.is-memory-preview .memory-check { top: 0; right: 3px; font-size: 11px; }

@media (min-width: 1050px) and (orientation: landscape) {
  .memory-board.count-40 { --memory-columns: 8; grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr)); }
  .memory-board.count-60 { --memory-columns: 10; grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .memory-shell { padding-inline: 10px; }
  .memory-tools { min-height: 65px; gap: 8px; padding: 8px; border-radius: 17px; }
  .memory-tools .activity-instruction { font-size: 15px; }
  .memory-tools .memory-actions { gap: 7px; }
  .memory-shell .memory-tools .game-action { width: 44px; height: 44px; min-height: 44px; padding: 7px; border-radius: 14px; }
  .memory-tools .game-action .game-action-icon { width: 25px; height: 27px; }
  .memory-tools .game-action-badge { right: -4px; top: -6px; min-width: 22px; height: 22px; padding-inline: 4px; font-size: 12px; }
  .memory-board, .memory-board.count-60 { gap: 4px; padding: 6px; border-width: 2px; }
  .memory-board.count-60 { --memory-columns: 6; grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr)); }
  .memory-shell .count-60 .memory-card { height: clamp(44px, calc((100dvh - 325px) / 10), 65px); padding: 13px 3px 3px; border-radius: 10px; }
  .is-memory-preview > .memory-play-panel { inset-inline: 6px; width: calc(100% - 12px); padding: 6px; border-radius: 18px; }
  .is-memory-preview .memory-tools { padding: 4px 3px 7px; margin-bottom: 4px; min-height: 65px; }
  .is-memory-preview .memory-board { gap: 3px; padding: 4px; }
  .memory-shell .is-memory-preview .memory-card { min-height: 0; height: 100%; padding: 11px 2px 2px; }
}
@media (max-height: 520px) {
  .is-memory-preview .memory-tools { min-height: 52px; padding-block: 2px; }
  .is-memory-preview .memory-instruction-copy small { display: none; }
  .is-memory-preview .memory-board { gap: 2px; padding: 3px; }
  .memory-shell .is-memory-preview .memory-card { padding-top: 0; border-width: 1px; border-radius: 5px; }
  .is-memory-preview .memory-card-number, .is-memory-preview .memory-check { display: none; }
}
@media (max-width: 350px) {
  /* Leave room for the desktop scrollbar as well as six 44px touch targets. */
  .memory-shell { padding-inline: 6px; }
  .memory-board.count-60 { gap: 3px; padding: 4px; }
  .is-memory-preview .memory-instruction-copy small { display: none; }
  .is-memory-preview .memory-tools .activity-instruction { font-size: 14px; line-height: 1.35; }
}
