/* Keep the activity and its controls in the available window. */
html, body { width: 100%; height: 100%; }
body { overflow: hidden; }
main {
  width: 100%; height: 100dvh; max-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
  gap: 0;
}
header { margin-bottom: 8px; }
.heading { margin-bottom: 8px; }
#viewport {
  min-width: 0; min-height: 0; width: 100%; height: 100%;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; background: transparent;
  container-type: size;
}
#scene {
  flex: none; width: min(100cqw, calc(100cqh * var(--image-ratio, 1672 / 941)));
  height: auto; aspect-ratio: var(--image-ratio, 1672 / 941); overflow: hidden;
  border-radius: 12px; background: #dfe8ef;
}
.toolbar { margin-top: 8px; }
#status { margin: 2px 0; min-height: 1.3em; font-size: 14px; line-height: 1.3; }
.picker { min-height: 40px; }
.picker select { min-height: 36px; padding-top: 5px; padding-bottom: 5px; }
@media (max-height: 500px) {
  main { padding: 6px 10px; }
  header { margin-bottom: 2px; font-size: 12px; }
  .heading { margin-bottom: 3px; }
  .heading h1 { font-size: 18px; }
  .heading p { display: none; }
  button, select { min-height: 36px; padding: 5px 12px; font-size: 13px; }
  .toolbar { margin-top: 3px; }
  #status { min-height: 1em; margin: 0; font-size: 12px; }
  .picker { min-height: 34px; }
  .picker select { min-height: 30px; }
}
@media (max-width: 380px) {
  .toolbar { gap: 4px; flex-wrap: nowrap; }
  .toolbar button { font-size: 12px; padding-left: 7px; padding-right: 7px; }
}
/* Explicit rows keep embedded mode (where the header is hidden) aligned. */
main > header { grid-row: 1; }
main > .heading { grid-row: 2; }
main > #viewport { grid-row: 3; }
main > .toolbar { grid-row: 4; }
main > #status { grid-row: 5; }
main > .picker { grid-row: 6; }
/* Override the original landscape width cap; sizing now follows available height. */
#viewport { max-width: none; margin: 0; }

/* Leave visible space around the full photo in both dialog modes. */
#answerDialog {
  --dialog-gutter: clamp(6px, 1.5vmin, 16px);
  width: min(1600px, calc(100vw - 2 * var(--dialog-gutter))); max-width: none;
  height: calc(100dvh - 2 * var(--dialog-gutter)); max-height: none;
  padding: var(--dialog-gutter); overflow: hidden;
}
#answerDialog[open] { display: flex; flex-direction: column; gap: 6px; }
#answerDialog .dialog-heading { flex: none; margin: 0; }
#closeAnswer { flex: none; }
.dialog-viewport {
  flex: 1; min-height: 0; min-width: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: var(--dialog-gutter);
  background: #e3ebf2;
  border-radius: 10px;
  container-type: size;
}
#answerDialog .scene {
  width: min(100cqw, calc(100cqh * var(--image-ratio, 1672 / 941)));
  height: auto; max-height: none; max-width: 100%;
  aspect-ratio: var(--image-ratio, 1672 / 941); margin: 0;
}
#dialogStatus { flex: none; min-height: 1.3em; margin: 0; font-size: 13px; line-height: 1.3; }
