/* The preview panel: the generated image (canvas) and the Save / Share buttons. */

.preview {
  min-width: 0;
  min-height: 0;
  background-color: var(--surface);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px); /* dotted "canvas" */
  background-size: 16px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 28px;
}

/* The image is wrapped in a button that opens it full screen (see ui/lightbox.js). */
.cv-zoom {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 14px;
  cursor: zoom-in;
  /* Fit the 9:16 image to the viewport height:
     viewport − app padding (40) − panel padding (56) − panel border (2) − gap + button (64) */
  width: min(100%, calc((100vh - 162px) * 9 / 16));
  width: min(100%, calc((100dvh - 162px) * 9 / 16));
}
#cv {
  display: block;
  width: 100%;
  height: auto;
  border-radius: inherit;
  box-shadow: var(--canvas-shadow);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 860px) {
  .cv-zoom {
    width: min(100%, calc(64vh * 9 / 16));
    width: min(100%, calc(64svh * 9 / 16));
    border-radius: 12px;
  }
  .actions {
    width: 100%;
  }
  .actions .btn {
    flex: 1;
    padding: 0 14px;
  }
}

/* ---- Enlarged view (lightbox) ---- */

/* The dialog covers the viewport (transparent) so a tap anywhere closes it; the frame
   holds the image and the ✕ and is what follows the finger when swiping. */
dialog.lightbox {
  --lightbox-width: min(90vw, calc(82vh * 9 / 16));
  --drag: 0; /* 0…1 while swiping, fades the backdrop (set from lightbox.js) */
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
  touch-action: none; /* the swipe is handled in JS; no page scroll or zoom meanwhile */
}
@supports (height: 1dvh) {
  dialog.lightbox {
    --lightbox-width: min(90vw, calc(82dvh * 9 / 16));
  }
}
dialog.lightbox[open] {
  display: grid;
  place-items: center;
}
dialog.lightbox::backdrop {
  background: rgba(10, 10, 9, calc(0.72 * (1 - var(--drag, 0))));
  backdrop-filter: blur(6px);
}

.lightbox-frame {
  position: relative;
  width: var(--lightbox-width);
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
}
.lightbox.dragging .lightbox-frame {
  transition: none;
}
.lightbox.closing .lightbox-frame {
  opacity: 0;
}
#lightboxCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Red ✕ above the top-right corner of the image, no border. */
.lightbox-close {
  position: absolute;
  bottom: calc(100% + 6px);
  inset-inline-end: -18px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  color: #ff453a;
}
.lightbox-close svg {
  width: 22px;
  height: 22px;
}
.lightbox-close:hover {
  color: #ff6961;
}
/* No ring around the ✕; keyboard focus is shown as a soft round highlight instead. */
.lightbox-close:focus {
  outline: none;
}
.lightbox-close:focus-visible {
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.lightbox-frame:focus {
  outline: none; /* focused on open only so the ✕ does not get focus (and a highlight) on touch */
}

/* ---- Donation dialog (shown after saving or sharing, see ui/donate.js) ---- */

/* Centred on every screen size, also on phones where other dialogs are bottom sheets. */
dialog.donate-dialog {
  width: min(380px, calc(100vw - 32px));
  height: fit-content;
  max-height: calc(100vh - 32px);
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.donate {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 24px 24px;
  text-align: center;
}
.donate-close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
}
.donate-icon {
  font-size: 40px;
  line-height: 1;
}
.donate h2 {
  margin: 4px 0 0;
  font-size: 19px;
  font-weight: 700;
}
.donate h2:focus {
  outline: none; /* focused on open only to keep the focus ring off the ✕ */
}
.donate p {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}
.donate-flag .flag {
  display: inline-block;
  width: 1.2em;
  height: auto;
  vertical-align: -0.15em;
  font-size: 1.05em;
  line-height: 1;
}
.donate-btn {
  width: 100%;
  text-decoration: none;
}
