/* Keep every generated image visible inside a stable result canvas. */
:root {
  --adaptive-result-canvas-height: 540px;
  --adaptive-tool-result-height: 455px;
}

.adaptive-result-grid {
  --result-columns: 1;
  --result-rows: 1;
  --result-gap: clamp(5px, 0.65vw, 10px);
  box-sizing: border-box;
  display: grid !important;
  grid-template-columns: repeat(var(--result-columns), minmax(0, 1fr)) !important;
  grid-template-rows: repeat(var(--result-rows), minmax(0, 1fr)) !important;
  grid-auto-flow: row;
  gap: var(--result-gap) !important;
  align-items: stretch;
  align-content: stretch !important;
  justify-items: stretch;
  overflow: hidden;
}

#resultGrid.adaptive-result-grid,
#skuResults.adaptive-result-grid {
  width: 100%;
  height: var(--adaptive-result-canvas-height);
  min-height: 0;
  max-height: var(--adaptive-result-canvas-height);
  flex: 0 0 var(--adaptive-result-canvas-height);
}

#resultGrid.adaptive-result-grid[data-result-count="0"] {
  display: none !important;
}

#skuResults.adaptive-result-grid[data-result-count="0"] {
  display: grid !important;
}

#skuResults.adaptive-result-grid > .empty-mini:only-child {
  width: 100%;
  height: 100% !important;
  min-height: 0 !important;
}

#toolResultGrid.adaptive-result-grid {
  width: 100%;
  height: 470px;
  min-height: 470px;
  max-height: 470px;
}

.tool-v2-stage:has(> .tool-v2-results.adaptive-result-grid) {
  height: var(--adaptive-tool-result-height);
  min-height: var(--adaptive-tool-result-height);
  max-height: var(--adaptive-tool-result-height);
}

.tool-v2-results.adaptive-result-grid {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  padding: 10px;
}

.adaptive-result-grid > img,
.adaptive-result-grid > article,
.adaptive-result-grid > article > img {
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
}

.adaptive-result-grid > img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  object-position: center;
}

.adaptive-result-grid > article {
  width: 100%;
  height: 100%;
  display: grid !important;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  align-content: stretch !important;
  overflow: hidden;
}

.adaptive-result-grid > article > img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  object-position: center;
}

@media (max-height: 760px) and (min-width: 761px) {
  :root {
    --adaptive-result-canvas-height: clamp(380px, calc(100svh - 220px), 540px);
    --adaptive-tool-result-height: clamp(360px, calc(100svh - 250px), 455px);
  }
}

@media (max-width: 760px) {
  :root {
    --adaptive-result-canvas-height: clamp(360px, 68svh, 540px);
    --adaptive-tool-result-height: clamp(360px, 68svh, 455px);
  }
}
