/*
 * The create dialog.
 *
 * One structure at every size: the dialog is a flex column whose active step
 * scrolls internally and whose action bar is a real footer held by layout —
 * not position: sticky — so overscroll can never lift it off the bottom edge.
 * On desktop it opens over the hero's left column so the phone stays visible.
 *
 * Everything visual reads tokens. The close control is the design system's
 * ring icon button; nothing here restyles it beyond its position.
 */

.create-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--jw-z-modal);
  display: none;
  place-items: center;
  padding: var(--jw-space-3);
  background: var(--jw-scrim);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.create-overlay.show { display: grid; }

.create-modal {
  width: min(560px, 100%);
  /* Same behaviour as desktop: capped to the visible viewport, the active
     step scrolls inside, the footer stays put. svh tracks mobile browser
     chrome correctly. */
  max-height: calc(100svh - var(--jw-space-6) * 2);
  display: flex;
  flex-direction: column;
  gap: var(--jw-space-4);
  overflow: hidden;
  border: 1px solid var(--jw-card-border);
  border-radius: var(--jw-radius-xl);
  background: var(--jw-modal-bg);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  /* The footer bar owns the bottom edge. */
  padding: var(--jw-modal-padding) var(--jw-modal-padding) 0;
  box-shadow: var(--jw-shadow-xl);
  animation: modal-pop 0.38s cubic-bezier(0.2, 0.9, 0.2, 1.15) both;
  /* Hairlines inside the dialog drop to the faint step: visible structure,
     no stark lines on either ground. */
  --jw-line: var(--jw-line-faint);
}

@media (min-width: 981px) {
  .create-overlay {
    place-items: start;
    padding:
      calc(var(--jw-topbar-height) + var(--jw-space-4))
      calc((100% - var(--jw-container)) / 2)
      var(--jw-space-6);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    overflow: hidden;
  }

  .create-modal {
    /* Matches the hero's left column so the phone stays uncovered. */
    width: min(560px, calc(var(--jw-container) * 0.54));
    max-height: calc(100svh - var(--jw-topbar-height) - var(--jw-space-12));
  }
}

/* --- Steps ---------------------------------------------------------------*/

.form-stage {
  position: relative;
  display: none;
  gap: var(--jw-space-4);
}

.create-modal.form .form-stage { display: grid; }

/* The active step is the scroll region. Its gutters reach the dialog's edge
   and pad the same distance back in, so anything the clip line crosses is
   transparent space — inner styling can never be cropped. */
.create-modal.form .form-stage,
.create-modal.ready .result-card,
.create-modal.building .progress-card {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: calc(var(--jw-modal-padding) * -1) calc(var(--jw-modal-padding) * -1) 0;
  padding: var(--jw-modal-padding) var(--jw-modal-padding) var(--jw-space-4);
}

.create-modal.form .build-mark,
.create-modal.form > .build-copy,
.create-modal.form .progress-card,
.create-modal.form .result-card {
  display: none;
}

.create-modal.ready .build-mark,
.create-modal.ready .build-copy,
.create-modal.ready .progress-card,
.create-modal.ready .form-stage {
  display: none;
}

.create-modal.ready .result-card {
  display: grid;
  border: 0;
  background: transparent;
  box-shadow: none;
  animation: ready-in 0.32s ease both;
}

/* --- Footer bar ----------------------------------------------------------*/

/* A real footer: the dialog's last flex child. Glass ground; the button sits
   a full modal-padding from every edge. Shown only with the form step. */
.form-actions {
  display: none;
  flex: none;
  gap: var(--jw-space-2);
  margin: 0 calc(var(--jw-modal-padding) * -1);
  padding: var(--jw-modal-padding);
  border-top: 1px solid var(--jw-line);
  background: var(--jw-modal-bg);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
}

.create-modal.form .form-actions { display: grid; }

.form-actions .status:empty { display: none; }

/* --- Close control -------------------------------------------------------*/

/* The ring icon button from the design system; only its position lives here.
   Aligned to the same gutter as the content on both axes. */
.modal-close {
  position: absolute;
  top: var(--jw-modal-padding);
  right: var(--jw-modal-padding);
  z-index: 3;
}

/* --- Content adjustments -------------------------------------------------*/

/* The dialog owns the padding; the form must not add its own. */
.create-modal .form {
  padding: 0;
  background: none;
}
.create-modal .template-gallery { grid-template-columns: 1fr; }

/* --- Scrollbars ----------------------------------------------------------*/

/* Visible only while the pointer is over the dialog, so at rest it reads as
   a clean panel. */
.create-modal.form .form-stage,
.create-modal.ready .result-card,
.create-modal.building .progress-card {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.create-modal:hover .form-stage,
.create-modal:hover .result-card,
.create-modal:hover .progress-card {
  scrollbar-color: var(--jw-line-strong) transparent;
}

.create-modal ::-webkit-scrollbar { width: 8px; }
.create-modal ::-webkit-scrollbar-track { background: transparent; }
.create-modal ::-webkit-scrollbar-thumb {
  border-radius: var(--jw-radius-pill);
  background: transparent;
}
.create-modal:hover ::-webkit-scrollbar-thumb { background: var(--jw-line-strong); }

/* --- Building state ------------------------------------------------------
 *
 * The same app icon as the homepage brand (mounted via data-logo="icon"),
 * floating gently with an ember pulse ringing off it. No spinning rainbows,
 * no capability pills - the step list below already says what is happening.
 * ------------------------------------------------------------------------ */

.build-mark {
  display: grid;
  justify-items: start;
  margin-bottom: var(--jw-space-4);
}

.build-mark .jw-app-icon {
  --jw-app-icon-size: 84px;
  --jw-app-icon-rim-width: 1.5px;
  animation: build-float 2.8s ease-in-out infinite;
}

.build-copy {
  display: grid;
  gap: 6px;
}

.create-modal.building .build-copy {
  margin-bottom: var(--jw-space-5);
}

.build-copy h2 {
  font-size: clamp(1.9rem, 5vw, 3rem);
  line-height: var(--jw-leading-snug);
  /* The step titles swap between one and two lines as the build advances;
     reserving the two-line box (plus the heading's descender padding from
     components.css) keeps the modal height from jumping. */
  min-height: calc(2em * var(--jw-leading-snug) + 0.14em);
}

.build-copy p {
  color: var(--muted);
  font-weight: 720;
}

/* The shared gutter rule pulls the scroll region up under the content
   above; in the building state nothing scrolls past it, so the pull-up
   just overlaps the copy. Keep the side bleed, drop the overlap. */
.create-modal.building .progress-card {
  margin-top: 0;
}

@keyframes build-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* --- The reveal -----------------------------------------------------------
 *
 * When the page is ready, the product IS the reveal: the hero device behind
 * the overlay carries the freshly created site (refreshHomePreview swaps it
 * in), so the device rises above the scrim and sharpens while everything
 * else stays blurred, and the dialog steps aside to present it.
 *
 * The blur animates on .phone-viewport - the sanctioned wrapper (it already
 * carries clip-path and the entrance fade). Never on .phone: filter there
 * flattens the preserve-3d chassis. The keyframe deliberately has no
 * fill-mode, so when it ends the filter property clears entirely and the 3D
 * context un-flattens.
 * ------------------------------------------------------------------------ */

@media (min-width: 1240px) {
  .create-overlay:has(.create-modal.ready) {
    justify-items: start;
    padding-left: clamp(24px, 7vw, 110px);
  }

  body.creating:has(.create-modal.ready) .phone-viewport {
    position: relative;
    z-index: calc(var(--jw-z-modal) + 1);
    animation: phone-unblur 1.2s var(--jw-ease-out);
  }
}

@keyframes phone-unblur {
  from { filter: blur(14px) saturate(0.82); }
  to { filter: blur(0px) saturate(1); }
}

@media (prefers-reduced-motion: reduce) {
  body.creating:has(.create-modal.ready) .phone-viewport { animation: none; }
}

/* --- Keyframes -----------------------------------------------------------*/

@keyframes shimmer {
  from { transform: translateX(-110%); }
  to { transform: translateX(110%); }
}

@keyframes modal-pop {
  from { transform: translateY(16px) scale(0.96); }
  to { transform: translateY(0) scale(1); }
}

@keyframes ready-in {
  from { transform: translateY(10px); }
  to { transform: translateY(0); }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes phone-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes phone-sheen {
  0% { opacity: 0; transform: translateX(-75%); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: translateX(75%); }
}

@keyframes hero-drift-out {
  0% { opacity: 1; transform: scale(1); filter: saturate(1); }
  100% { opacity: 0.2; transform: scale(1.045) translateY(-6px); filter: saturate(0.92); }
}

@keyframes hero-drift-in {
  0% { opacity: 0; transform: scale(1.08) translateY(10px); filter: saturate(0.9) blur(3px); }
  46% { opacity: 1; filter: saturate(1.05) blur(0); }
  100% { opacity: 1; transform: scale(1); filter: saturate(1); }
}

@keyframes content-slide-in {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes tile-cascade {
  0% { transform: translateY(14px) rotateX(10deg) scale(0.97); filter: saturate(0.94) brightness(0.94); }
  100% { transform: translateY(0) rotateX(0) scale(1); filter: saturate(1) brightness(1); }
}

@keyframes dot-load {
  0% { transform: scaleX(0); }
  100% { transform: scaleX(1); }
}

/* --- Legacy target view (unchanged) --------------------------------------*/

.view-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.38fr);
  gap: 22px;
  align-items: start;
  padding: 28px 0 64px;
}

/* ---------------------------------------------------------------------------
 * Building progress and ready-state result internals
 *
 * Everything the dialog shows while a page is being made and once it is
 * ready: the progress card, the preview pair, the QR cards, links, and the
 * one-time owner key. Shared primitives (.secret, .link-list) stay in
 * base.css - the target view uses them too.
 * ------------------------------------------------------------------------ */
.progress-card {
  display: none;
  gap: 12px;
  padding: var(--jw-space-5);
  border: 1px solid var(--jw-line);
  border-radius: var(--jw-radius-lg);
  background: var(--jw-surface-raised);
  box-shadow: var(--jw-shadow-sm);
}

.progress-card.show { display: grid; }

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 850;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: var(--jw-radius-pill);
  background: var(--jw-surface-sunken);
  border: 1px solid var(--jw-line-faint);
}

.progress-fill {
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--jw-accent), var(--jw-accent-strong));
  transition: width 0.35s ease;
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: shimmer 1.15s linear infinite;
}

.progress-steps {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 690;
}

.progress-steps span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-steps span::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: var(--jw-radius-pill);
  background: var(--jw-line-strong);
}

.progress-steps span.done {
  color: var(--ink);
}

.progress-steps span.done::before {
  background: var(--jw-accent);
}

.result-card {
  display: none;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--jw-line);
  border-radius: var(--jw-radius-lg);
  background: var(--jw-surface-raised);
}

.result-card.show { display: grid; }

/* Mobile ready state: the desktop reveal (the hero device sharpening behind
   the dialog) has no room below 1240px, so the page itself leads the result
   card - preview on top, details underneath. */
.result-site-frame { display: none; }

@media (max-width: 1239px) {
  .result-site-frame.show {
    position: relative;
    display: block;
    height: 54svh;
    flex: none;
    padding-top: 38px;
    border: 1px solid var(--jw-line-strong);
    border-radius: 22px;
    overflow: hidden;
    /* The status strip keeps the page below it, iOS style. */
    background: var(--jw-black);
  }

  .result-site-frame.show::before {
    content: "9:41";
    position: absolute;
    top: 0;
    left: 0;
    height: 38px;
    display: flex;
    align-items: center;
    padding-left: 24px;
    color: var(--jw-white);
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
  }

  .result-site-frame.show::after {
    content: "";
    position: absolute;
    top: 0;
    right: 18px;
    width: 56px;
    height: 38px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='12' viewBox='0 0 60 12' fill='%23fafafa'%3E%3Crect x='0' y='7' width='3' height='5' rx='1'/%3E%3Crect x='4.5' y='5' width='3' height='7' rx='1'/%3E%3Crect x='9' y='3' width='3' height='9' rx='1'/%3E%3Crect x='13.5' y='1' width='3' height='11' rx='1'/%3E%3Cpath d='M28.5 3.6a8.5 8.5 0 0 0-6.4 2.4l1.5 1.6a6.4 6.4 0 0 1 9.8 0l1.5-1.6a8.5 8.5 0 0 0-6.4-2.4zm0 4.6c-1 0-2 .4-2.7 1.2l2.7 2.8 2.7-2.8a3.8 3.8 0 0 0-2.7-1.2z'/%3E%3Crect x='40' y='1.5' width='16' height='9' rx='2.6' fill='none' stroke='%23fafafa' stroke-opacity='.5'/%3E%3Crect x='42' y='3.5' width='10' height='5' rx='1.4'/%3E%3Cpath d='M57.5 4.5v3a2 2 0 0 0 0-3z'/%3E%3C/svg%3E") center / 56px 11px no-repeat;
    pointer-events: none;
  }

  .result-site-frame iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #fff;
  }
}

.result-head {
  display: grid;
  gap: 4px;
}

.result-head strong {
  font-size: 1.35rem;
  line-height: 1.05;
}

.result-head span {
  color: var(--muted);
  font-weight: 680;
}

.result-links {
  display: grid;
  gap: 10px;
}

.result-preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.result-preview {
  display: grid;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--jw-line);
  border-radius: var(--jw-radius-md);
  background: var(--jw-surface);
  color: var(--jw-text-primary);
  box-shadow: var(--jw-shadow-sm);
}

.result-preview:hover {
  transform: translateY(-1px);
  box-shadow: var(--jw-shadow-md);
}

.preview-shot {
  position: relative;
  min-height: 136px;
  background:
    linear-gradient(135deg, var(--jw-accent-soft), transparent 70%),
    var(--jw-surface-sunken);
  overflow: hidden;
}

.preview-shot img {
  width: 100%;
  height: 136px;
  object-fit: cover;
  display: block;
}

.preview-shot.profile {
  display: grid;
  place-items: center;
  min-height: 136px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 204, 77, 0.24), transparent 34%),
    radial-gradient(circle at 78% 18%, rgba(32, 197, 168, 0.22), transparent 34%),
    linear-gradient(180deg, #111, #252525);
}

/* Same treatment as the page shot beside it: a flush cover image, no ring,
   no inner card - the two previews read as one pair. */
.profile-avatar-preview {
  width: 100%;
  height: 136px;
  border: 0;
  border-radius: 0;
  object-fit: cover;
  background: transparent;
  box-shadow: none;
}

.preview-body {
  display: grid;
  gap: 5px;
  padding: 12px;
}

.preview-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-title {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 940;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-url {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

/* The design system's ghost button, stretched full width. */
.change-profile-button { justify-content: center; }

.result-qr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.result-qr-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--jw-line);
  border-radius: var(--jw-radius-md);
  background: var(--jw-surface);
  box-shadow: var(--jw-shadow-sm);
}

.result-qr-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--jw-radius-sm);
  /* QR codes scan against white; this ground is functional, not thematic. */
  background: var(--jw-white);
  object-fit: contain;
}

/* Dark theme flips the code to soft-white modules on black - brightness
   pulls pure white down to the fafafa family so it does not glare. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .result-qr-card img { filter: invert(1) brightness(0.98); }
}
[data-theme="dark"] .result-qr-card img { filter: invert(1) brightness(0.98); }

.result-qr-copy {
  display: grid;
  gap: 4px;
  text-align: center;
}

.result-qr-copy strong {
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.result-qr-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-brand {
  min-height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--jw-radius-sm);
  background: var(--jw-black);
  color: var(--jw-white);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.result-link {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.result-link.primary {
  background: var(--jw-black);
  color: var(--jw-white);
  border-color: rgba(255, 255, 255, 0.16);
}

.result-link span:first-child {
  color: inherit;
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.result-link strong {
  overflow: hidden;
  font-size: 1.03rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.more-button {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--jw-radius-pill);
  background: var(--jw-surface);
  color: var(--jw-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
}
.more-button:hover { color: var(--jw-text-primary); border-color: var(--jw-line-strong); }

.owner-key {
  display: none;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.owner-key.show { display: grid; }

.identity-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--jw-line);
  border-radius: var(--jw-radius-md);
  background: var(--jw-surface-sunken);
}

.identity-card img {
  width: 54px;
  height: 54px;
  border-radius: var(--jw-radius-md);
  object-fit: cover;
  background: var(--jw-surface);
}

.identity-card strong,
.identity-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
