/* Prompt Box — styles for blockquotes upgraded to prompt boxes, and for an
 * image paired with the prompt that follows it.
 *
 * It reads the active theme's colour tokens (--cd-*), so the box matches the
 * theme in light and dark mode. Every token has a fallback, so the box still
 * looks right on a theme that does not define them. Override these from a
 * theme or Customizer CSS to restyle:
 *
 *   --bhpb-accent        button / selection colour  (default: the theme's primary)
 *   --bhpb-height        height of the prompt area on its own    (default 350px)
 *   --bhpb-pair-height   height of the prompt area under an image
 *                        in the one-column layout                (default 280px)
 *   --bhpb-pair-min      shortest a side-by-side pair may be     (default 27rem)
 */

.bhpb-source[hidden] { display: none !important; }

.bhpb,
.bhpb-pair {
  --bhpb-primary: var(--bhpb-accent, var(--cd-primary, #2563eb));
  --bhpb-primary-hover: var(--cd-primary-hover, color-mix(in srgb, var(--bhpb-primary) 84%, #000));
  --bhpb-primary-ink: var(--cd-primary-ink, var(--bhpb-primary));
  --bhpb-primary-soft: var(--cd-primary-soft, color-mix(in srgb, var(--bhpb-primary) 12%, transparent));
  --bhpb-raised: rgb(var(--cd-raised, 255 255 255));
  --bhpb-surface: rgb(var(--cd-surface, 245 247 250));
  --bhpb-ink: rgb(var(--cd-ink, 14 23 38));
  --bhpb-ink-2: rgb(var(--cd-ink-2, 52 64 84));
  --bhpb-muted: rgb(var(--cd-muted, 100 112 132));
  --bhpb-line: rgb(var(--cd-line, 226 230 237));
  --bhpb-line-2: rgb(var(--cd-line-2, 203 210 221));
  --bhpb-shadow: 0 1px 2px rgb(var(--cd-shadow, 16 24 40) / .06);
  --bhpb-radius: 1rem;
}

/* ── The box ──────────────────────────────────────────────────────────── */
.bhpb {
  display: flex;
  flex-direction: column;
  margin: 1.5rem 0;
  border: 1px solid var(--bhpb-line);
  border-radius: var(--bhpb-radius);
  overflow: hidden;
  background: var(--bhpb-raised);
  box-shadow: var(--bhpb-shadow);
  color: var(--bhpb-ink);
  font-family: var(--cd-font, inherit);
  font-style: normal;
  font-weight: 400;
  quotes: none;
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.bhpb *, .bhpb *::before, .bhpb *::after { box-sizing: border-box; }
.bhpb:focus-within {
  border-color: var(--bhpb-primary);
  box-shadow: 0 0 0 4px var(--bhpb-primary-soft);
}

/* ── Header ───────────────────────────────────────────────────────────── */
.bhpb__bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .4rem .5rem .4rem .9rem;
  background: var(--bhpb-surface);
  border-bottom: 1px solid var(--bhpb-line);
}
.bhpb__title {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-family: var(--cd-font-head, inherit);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--bhpb-ink-2);
}
.bhpb__title svg { width: 1rem; height: 1rem; flex-shrink: 0; color: var(--bhpb-primary); }

.bhpb__copy {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  height: 2rem;
  margin: 0;
  padding: 0 .85rem;
  font: inherit;
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1;
  color: #fff;
  background: var(--bhpb-primary);
  border: 1px solid transparent;
  border-radius: .5rem;
  cursor: pointer;
  transition: background-color .15s ease;
}
.bhpb__copy:hover { background: var(--bhpb-primary-hover); }
.bhpb__copy svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.bhpb__copy.is-done { background: #16a34a; }
.bhpb__copy.is-failed { background: #dc2626; }

/* ── Prompt text: scrolls ─────────────────────────────────────────────── */
.bhpb__text {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: var(--bhpb-height, 350px);
  min-height: 0;
  margin: 0;
  padding: .9rem 1.05rem;
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  overflow-y: auto;
  background: transparent;
  color: var(--bhpb-ink);
  font-family: var(--cd-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: .875rem;
  font-style: normal;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: var(--bhpb-line-2) transparent;
}
.bhpb__text::selection { background: var(--bhpb-primary-soft); }
.bhpb__text::-webkit-scrollbar { width: 10px; }
.bhpb__text::-webkit-scrollbar-track { background: transparent; }
.bhpb__text::-webkit-scrollbar-thumb {
  background: var(--bhpb-line-2);
  border: 2px solid transparent;
  border-radius: 9999px;
  background-clip: content-box;
}
.bhpb__text::-webkit-scrollbar-thumb:hover {
  background: var(--bhpb-muted);
  background-clip: content-box;
}

/* ── Controls: pinned under the text, two compact rows ────────────────── */
.bhpb__vars {
  flex: none;
  display: grid;
  gap: .5rem;
  padding: .6rem .7rem .7rem;
  background: var(--bhpb-surface);
  border-top: 1px solid var(--bhpb-line);
}
.bhpb__row { display: flex; align-items: center; gap: .3rem; min-width: 0; }
.bhpb__label {
  flex: 0 0 auto;
  margin-right: .25rem;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--bhpb-muted);
}

/* Row 1: aspect ratio chips, the theme's chip look, each with a frame in its own shape. */
.bhpb__chip {
  flex: 1 1 0;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  height: 1.9rem;
  margin: 0;
  padding: 0 .2rem;
  font: inherit;
  font-size: .75rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--bhpb-ink-2);
  background: var(--bhpb-raised);
  border: 1px solid var(--bhpb-line);
  border-radius: 9999px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.bhpb__chip:hover { border-color: var(--bhpb-primary); color: var(--bhpb-primary-ink); }
.bhpb__chip[aria-pressed="true"] {
  color: #fff;
  background: var(--bhpb-primary);
  border-color: var(--bhpb-primary);
}
.bhpb__ar {
  display: inline-block;
  flex: none;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  opacity: .85;
}

/* Row 2: style and lighting dropdowns, half each. */
.bhpb__row--selects {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: .5rem;
}
.bhpb__select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 2.1rem;
  margin: 0;
  padding: 0 1.8rem 0 .75rem;
  font: inherit;
  font-size: .8125rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--bhpb-ink-2);
  text-overflow: ellipsis;
  background-color: var(--bhpb-raised);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23647084' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .55rem center;
  background-size: .85rem;
  border: 1px solid var(--bhpb-line-2);
  border-radius: .5rem;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.bhpb__select:hover { border-color: var(--bhpb-primary); }
.bhpb__select:focus { outline: none; border-color: var(--bhpb-primary); box-shadow: 0 0 0 3px var(--bhpb-primary-soft); }
.bhpb__select.is-set { color: var(--bhpb-ink); border-color: var(--bhpb-primary); background-color: var(--bhpb-primary-soft); }
.bhpb__select option { color: var(--bhpb-ink); background-color: var(--bhpb-raised); font-weight: 400; }

.bhpb__copy:focus-visible,
.bhpb__chip:focus-visible {
  outline: 2px solid var(--bhpb-primary);
  outline-offset: 2px;
}

/* ── Image + prompt pair ──────────────────────────────────────────────────
 * Built on the server (see src/App.php). The whole pair is ONE card: a single
 * border and corner radius around the image and the box, no gap between them,
 * and a hairline where they meet. One column by default, image first. Wide
 * containers get two equal columns, and the prompt box takes exactly the
 * height of the image: the image alone sets the row height, the box is laid
 * over that cell, and the text scrolls in whatever the bar and controls leave.
 * A container query keeps this right when a sidebar narrows the content.
 */
.bhpb-pair { container-type: inline-size; margin: 1.5rem 0; }
.bhpb-pair__grid {
  display: grid;
  gap: 0;
  border: 1px solid var(--bhpb-line);
  border-radius: var(--bhpb-radius);
  overflow: hidden;
  background: var(--bhpb-raised);
  box-shadow: var(--bhpb-shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.bhpb-pair__grid:focus-within {
  border-color: var(--bhpb-primary);
  box-shadow: 0 0 0 4px var(--bhpb-primary-soft);
}

.cd-prose .bhpb-pair .bhpb-pair__media,
.bhpb-pair .bhpb-pair__media figure { margin: 0; }
.bhpb-pair .bhpb-pair__media { min-width: 0; background: var(--bhpb-surface); }
.bhpb-pair .bhpb-pair__media figure { width: auto !important; max-width: 100% !important; float: none; } /* resized images carry an inline pixel width */
.bhpb-pair .bhpb-pair__media img,
.cd-prose .bhpb-pair .bhpb-pair__media img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0;
  border-radius: 0;
}
.bhpb-pair .bhpb-pair__media figcaption { margin: 0; padding: .5rem .75rem; text-align: center; font-size: .875rem; color: var(--bhpb-muted); }

.bhpb-pair .bhpb-pair__prompt { min-width: 0; border-top: 1px solid var(--bhpb-line); }
.bhpb-pair .bhpb-pair__prompt .bhpb {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.bhpb-pair .bhpb-pair__prompt .bhpb:focus-within { box-shadow: none; }
.bhpb-pair .bhpb-pair__prompt .bhpb__text { height: var(--bhpb-pair-height, 280px); }

@container (min-width: 600px) {
  .bhpb-pair__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(var(--bhpb-pair-min, 27rem), auto);
    align-items: stretch;
  }
  .bhpb-pair .bhpb-pair__media figure { height: 100%; }
  .bhpb-pair .bhpb-pair__media img,
  .cd-prose .bhpb-pair .bhpb-pair__media img { height: 100%; object-fit: cover; }

  .bhpb-pair .bhpb-pair__prompt { position: relative; border-top: 0; border-left: 1px solid var(--bhpb-line); }
  .bhpb-pair .bhpb-pair__prompt > .bhpb,
  .bhpb-pair .bhpb-pair__prompt > blockquote:not([hidden]) {
    position: absolute;
    inset: 0;
    margin: 0;
  }
  .bhpb-pair .bhpb-pair__prompt > blockquote:not([hidden]) { overflow: auto; } /* no-JS fallback */
  .bhpb-pair .bhpb-pair__prompt .bhpb__text { height: auto; flex: 1 1 0; }
}

@media (max-width: 640px) {
  .bhpb__text { font-size: .8125rem; }
}

@media print {
  .bhpb__vars, .bhpb__copy { display: none; }
}
