/* The generation dialogs, Background and Visualize, and what every generation shows while it runs,
   the fill creator's too. */

/* The ring is an outline, so the box keeps its size and nothing around it moves. It is drawn inside
   the field's edge, so a scrolling column the field touches can't cut it. */
input.is-missing {
  border-color: var(--danger);
  outline: 2px solid var(--danger);
  outline-offset: -2px;
  animation: missing-input-blink 0.3s ease-in-out 3;
}

input.is-missing::placeholder {
  color: var(--danger);
  opacity: 1;
}

@keyframes missing-input-blink {
  50% {
    outline-color: transparent;
    border-color: var(--line-4);
  }
}

@media (prefers-reduced-motion: reduce) {
  input.is-missing {
    animation: none;
  }
}

/* The generation dialogs: a body that scrolls on its own and a foot that stays. They size to what
   they hold, and those with columns keep one height, so a list filling in moves nothing. */
#reusableModal .reusable-modal-content[data-generate] {
  height: auto;
  text-align: left;
}

#reusableModal .reusable-modal-content[data-columns] {
  --columns-sheet-height: min(640px, 88dvh);
  /* The height the background dialog's title, fields and foot take around its style grid, and
     around the lighting sample; the style rows and the sample share what is left. */
  --style-grid-room: 372px;
  --lighting-sample-room: 430px;
  height: var(--columns-sheet-height);
}

#generateDialogBalance {
  display: inline-block;
}

/* The body scrolls, so it clips what it holds. Its edges sit just outside the column's, so a field's
   focus ring or flag, drawn outside the field, shows whole while the fields stay where they were. */
.generate-dialog-body {
  container: generate-dialog / inline-size;
  flex: 1 1 auto;
  min-height: 0;
  margin-inline: calc(-1 * var(--ring-room));
  padding-inline: var(--ring-room);
  overflow: hidden auto;
  overscroll-behavior: contain;
  --ring-room: 4px;
  --focus-ring-offset: -2px;
}

.generate-dialog-foot {
  position: relative;
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line-2);
}

.generate-dialog-side {
  flex: 1 1 0;
  min-width: 0;
  color: var(--ink-3);
  font-size: 0.75rem;
  line-height: 1.35;
}

.generate-dialog-foot > button {
  flex: none;
  min-height: 44px;
  margin: 0;
  padding-inline: 20px;
  white-space: nowrap;
}

.generate-dialog-label {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-6);
  font-size: 0.85rem;
  font-weight: 500;
}

.generate-dialog .generate-dialog-hint {
  margin: 0 0 6px;
  color: var(--ink-4);
  font-size: 0.75rem;
}

.generate-dialog-strip {
  --strip-gap: 6px;
  display: flex;
  gap: var(--strip-gap);
  padding-bottom: 4px;
  overflow: auto hidden;
  scrollbar-width: none;
  --focus-ring-offset: -2px;
}

.generate-dialog-thumbs img {
  flex: none;
  width: var(--thumb-size, 64px);
  height: var(--thumb-size, 64px);
  border: 1px solid var(--line-3);
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
}

.choice-group {
  display: flex;
  gap: 6px;
}

.choice-group button {
  display: grid;
  flex: 1 1 0;
  gap: 4px;
  place-content: center;
  place-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--line-4);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-6);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

/* A shape takes the room its label leaves, centred, so the labels under shapes of different heights
   share a line. */
.choice-group .choice-group-shaped {
  grid-template-rows: 1fr auto;
  align-content: stretch;
}

.choice-group button[aria-pressed="true"] {
  border-color: var(--premium);
  background: var(--premium-tint);
  color: var(--premium);
  font-weight: 600;
}

.choice-group-shape {
  display: block;
  box-sizing: border-box;
  border: 2px solid currentColor;
  border-radius: 2px;
}

/* The hints share one cell, the hidden ones kept for their height. */
.choice-group-note {
  display: grid;
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-style: italic;
  line-height: 1.4;
}

.choice-group-note > span {
  grid-area: 1 / 1;
}

.choice-group-note > span[hidden] {
  display: block;
  visibility: hidden;
}

.generate-dialog-columns,
.generate-dialog-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

#backgroundPrompt {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-4);
  border-radius: 6px;
}

.background-style {
  flex: none;
  box-sizing: border-box;
  width: 76px;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--line-3);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-6);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.background-style[aria-pressed="true"] {
  border-color: var(--premium);
  box-shadow: inset 0 0 0 1px var(--premium);
}

/* Square, as the style pictures are, so each shows whole. */
.background-style img,
.background-style-custom {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface-2);
  color: var(--ink-2);
  object-fit: cover;
}

.background-style-name {
  display: block;
  padding: 3px 2px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.background-lighting {
  display: flex;
  gap: 10px;
  align-items: center;
}

.background-lighting-sample {
  flex: none;
  width: 56px;
  height: 56px;
  border: 1px solid var(--line-1);
  border-radius: 6px;
  object-fit: cover;
}

.background-lighting-controls {
  flex: 1 1 0;
  min-width: 0;
}

#backgroundLighting {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding-right: 2.25em;
  border: 1px solid var(--line-4);
  border-radius: 6px;
}

.background-lighting-hint {
  margin-top: 2px;
  color: var(--ink-3);
  font-size: 0.72rem;
}

/* Two columns as soon as the dialog has the width for them. */
@container generate-dialog (min-width: 500px) {
  .generate-dialog-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
  }
}

/* With the height as well, every style shows at once. Each card is as wide as its square picture,
   which shrinks whole to fit the sheet once the fields around it have their room; the row starts under
   the Style label, with the strip's even gaps. */
.background-styles {
  grid-template-columns: repeat(
    var(--style-columns),
    min(
      calc((100% - (var(--style-columns) - 1) * var(--strip-gap)) / var(--style-columns)),
      calc((var(--columns-sheet-height) - var(--style-grid-room)) / var(--style-rows))
    )
  );
  justify-content: start;
}

@container generate-dialog (min-width: 640px) {
  @media (min-height: 682px) {
    .background-styles {
      --style-columns: 3;
      --style-rows: 3;
      display: grid;
      overflow: visible;
    }

    .background-style {
      width: auto;
    }
  }
}

/* A short laptop's third row would leave the cards too narrow for their names, so the styles take two
   rows of five, as long as the column fits five cards of the strip's width; a narrower one keeps the strip. */
@container generate-dialog (min-width: 828px) {
  @media (min-height: 601px) and (max-height: 681px) {
    .background-styles {
      --style-columns: 5;
      --style-rows: 2;
      display: grid;
      overflow: visible;
    }

    .background-style {
      width: auto;
    }
  }
}

/* Visualize's finishes: a sample render each, with its name under it. */
.finish-grid {
  display: grid;
  gap: 8px;
}

.finish-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  padding: 4px 4px 8px;
  border: 2px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.finish-card[aria-pressed="true"] {
  border-color: var(--premium);
}

.finish-card img {
  width: 100%;
  max-height: 44dvh;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  object-fit: cover;
  object-position: 50% 30%;
}

.finish-card span {
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.1;
  text-align: center;
}

/* The user's own row leads the dialog. With nothing of theirs it steps aside; while their list is on
   its way it keeps its place, with where the pictures will go, so the list landing moves nothing. */
.generate-dialog-yours {
  margin-bottom: 10px;
}

.generate-dialog-yours.is-empty:not(.is-loading) {
  display: none;
}

.generate-dialog-yours.is-loading .generate-dialog-thumbs:empty::before {
  content: "";
  flex: none;
  width: calc(3 * var(--thumb-size, 64px) + 2 * var(--strip-gap));
  height: var(--thumb-size, 64px);
  border-radius: 6px;
  background: repeating-linear-gradient(to right, var(--surface-2) 0 var(--thumb-size, 64px), transparent var(--thumb-size, 64px) calc(var(--thumb-size, 64px) + var(--strip-gap)));
}

/* Rotating "while you wait" tip (#610). */
.generated-results-tip {
  width: 100%;
  max-width: 360px;
  margin: 8px auto 2px;
  padding: 8px 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-6);
  background: var(--surface-1);
  border-radius: 8px;
  transition: opacity 0.2s ease;
}

/* A short screen gives the dialog's edges to its fields: the sheet takes nearly all the height, the
   space around the title shrinks, and the user's own row keeps to a line of words over smaller
   pictures, so the fields still start in the first view. */
@media (max-height: 600px) {
  #reusableModal .reusable-modal-content[data-generate] {
    --columns-sheet-height: calc(100dvh - 16px);
    --sheet-title-gap: 8px;
    max-height: calc(100dvh - 16px);
  }

  /* The finish pictures give up the height the dialog's title, intro, foot and "More options" need,
     so their names show clear of the pill without a scroll. */
  .finish-card img {
    --finish-room: 300px;
    max-height: min(44dvh, calc(100dvh - var(--finish-room)));
  }

  .generate-dialog-yours {
    --thumb-size: 48px;
    display: flex;
    flex-wrap: wrap;
    column-gap: 8px;
    align-items: baseline;
  }

  .generate-dialog-yours .generate-dialog-thumbs {
    flex: 1 0 100%;
  }

  /* There is room for the wait note above the foot, not for a tip under it too. */
  .generated-results-tip {
    display: none;
  }
}

@media (min-width: 769px) and (min-height: 501px) and (max-height: 600px) {
  #reusableModal .reusable-modal-content[data-generate] {
    padding-block: 12px;
  }
}

/* A laptop gives the dialog a fixed width, and a two-column one all the width it can use. */
@media (min-width: 769px) and (min-height: 501px) {
  #reusableModal .reusable-modal-content[data-generate] {
    width: 480px;
  }

  /* A phone's sheet title has this gap already (.sheet-title). */
  [data-generate] .sheet-title {
    margin-bottom: var(--sheet-title-gap, 12px);
    text-align: center;
  }

  #reusableModal .reusable-modal-content[data-columns] {
    width: min(920px, calc(100vw - 32px));
  }
}

@container generate-dialog (min-width: 500px) {
  @media (min-height: 601px) {
    /* The sample shows what the choice does, so it takes the room the column has left. */
    .background-lighting {
      align-items: flex-start;
    }

    .background-lighting-sample {
      --sample-size: min(160px, calc(var(--columns-sheet-height) - var(--lighting-sample-room)));
      width: var(--sample-size);
      height: var(--sample-size);
    }
  }
}
