/* Create — app/create.tsx (original styling), plus the shared generating
   overlay (.gen-*) used by create and the post-checkout screen. */

.screen-create {
  padding-bottom: var(--safe-bottom);
}

.screen-create .create-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Upload phase ---------- */

.screen-create .upload-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* Clear of the floating bottom bar, like the app (paddingBottom 140). */
  padding: 0 var(--s-lg) 140px;
}

.screen-create .upload-zone {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-md) var(--s-xl);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-xl);
  text-align: center;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.screen-create .upload-zone.is-drag {
  background: var(--accent-tint);
  border-color: var(--accent);
}

.screen-create .upload-icon {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--text-3);
}

.screen-create .upload-icon .spinner {
  display: none;
  width: 28px;
  height: 28px;
  border-color: var(--accent);
  border-right-color: transparent;
}

.screen-create .upload-zone.is-loading .upload-icon ion-icon {
  display: none;
}

.screen-create .upload-zone.is-loading .upload-icon .spinner {
  display: block;
}

.screen-create .upload-title {
  margin: var(--s-md) 0 0;
  color: var(--text);
}

.screen-create .upload-sub {
  margin: var(--s-xxs) 0 0;
  line-height: 1.35;
  color: var(--text-2);
  text-wrap: balance;
}

.screen-create .pick-row {
  width: 100%;
  max-width: 248px;
  margin-top: var(--s-xl);
  display: flex;
  flex-direction: column;
  gap: var(--s-sm);
}

/* Accent-tint pills (the app's tinted picker button, with labels). */
.screen-create .pick-btn {
  position: relative;
  height: 52px;
  padding: 0 var(--s-lg);
  border-radius: var(--r-pill);
  background: var(--accent-tint);
  color: var(--accent-dark);
  box-shadow: var(--sh-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-xs);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.screen-create .pick-btn ion-icon {
  font-size: 22px;
  color: var(--accent);
}

.screen-create .pick-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.screen-create .upload-zone.is-loading .pick-btn {
  opacity: 0.55;
  pointer-events: none;
}

/* Visually hidden but still a real, tappable file input (not display:none). */
.screen-create .file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  pointer-events: none;
}

/* ---------- Photo + prompt phases ---------- */

.screen-create .close-row {
  flex-shrink: 0;
  display: flex;
  padding: 0 var(--s-lg);
  margin-bottom: var(--s-xs);
}

/* 36px buttons with a 44px touch target. */
.screen-create .hit-44 {
  position: relative;
}
.screen-create .hit-44::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: inherit;
}

.screen-create .photo-card {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 var(--s-lg);
  border-radius: var(--r-xl);
  overflow: hidden;
  background: var(--surface-muted);
  isolation: isolate;
  transform: translateZ(0); /* Safari: clip the blurred photo to the radius */
}

.screen-create .photo-card .photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 0.5s ease, transform 0.5s var(--ease-out);
}

.screen-create .photo-card.is-processing .photo {
  filter: blur(22px) saturate(1.15);
  transform: scale(1.18);
}

.screen-create .expand-btn {
  position: absolute;
  right: var(--s-sm);
  bottom: var(--s-sm);
  z-index: 3;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.screen-create .expand-btn::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}

.screen-create[data-phase='processing'] .photo-card {
  margin-bottom: var(--s-sm);
}

/* While generating, the controls fade out and can't be tapped. */
.screen-create .close-row .icon-btn,
.screen-create .expand-btn {
  transition: opacity 0.25s ease, transform 0.35s var(--spring);
}
.screen-create[data-phase='processing'] .close-row .icon-btn,
.screen-create[data-phase='processing'] .expand-btn {
  opacity: 0;
  pointer-events: none;
}

.screen-create .prompt-area {
  flex-shrink: 0;
  padding: 5px var(--s-lg) 0;
}

/* Chips row; the vertical padding gives each 30px chip a 44px touch target. */
.screen-create .idea-row {
  gap: var(--s-xs);
  padding: 7px 0;
  margin-bottom: 5px;
}

.screen-create .idea-chip {
  position: relative;
  flex-shrink: 0;
  padding: 7px var(--s-sm);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  line-height: 13px;
  white-space: nowrap;
}
.screen-create .idea-chip::after {
  content: '';
  position: absolute;
  inset: -7px -4px;
}

.screen-create .input-row {
  display: flex;
  align-items: flex-end;
  padding: var(--s-xs);
  margin-bottom: 6px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-xl);
  transition: border-color 0.2s ease;
}
.screen-create .input-row:focus-within {
  border-color: var(--border-strong);
}

.screen-create .prompt-input {
  flex: 1;
  min-width: 0;
  /* 44px tall touch target; the negative margin keeps the row's 36px look. */
  height: 44px;
  max-height: 104px;
  margin: -4px 0;
  padding: 12px 10px 12px var(--s-sm);
  border: 0;
  outline: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* 16px+ keeps iOS from zooming on focus */
  line-height: 20px;
  resize: none;
  overflow-y: hidden;
  -webkit-appearance: none;
  appearance: none;
}
.screen-create .prompt-input::placeholder {
  color: var(--text-3);
  opacity: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.screen-create .send-btn {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--charcoal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: opacity 0.2s ease, transform 0.35s var(--spring);
}
.screen-create .send-btn::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
}
.screen-create .send-btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}
.screen-create .send-btn .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  border-color: #fff;
  border-right-color: transparent;
}

/* Keyboard open (see syncViewport): give the photo the header's room. */
.screen-create.kb-open {
  padding-bottom: 0;
}
.screen-create.kb-open .app-header {
  display: none;
}
/* Save room for the input while typing. */
.screen-create.kb-open .ai-note {
  display: none;
}
.screen-create.kb-open .input-row {
  margin-bottom: var(--s-sm);
}

/* AI provider disclosure under the input (prompt phase). */
.screen-create .ai-note {
  margin: 0 0 var(--s-xs);
  padding: 0 var(--s-xs);
  text-align: center;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
  text-wrap: balance;
}
.screen-create .ai-note a {
  display: inline-block;
  padding: 12px 4px;
  margin: -12px -4px;
  color: var(--text-2);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Template flow (a template is selected: no prompt step) ---------- */

/* Compact card for the selected template: after-thumbnail, title, description. */
.screen-create .tpl-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--s-sm);
  padding: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-soft);
}

.screen-create .upload-wrap.has-template .tpl-head {
  margin-bottom: var(--s-sm);
}

.screen-create .tpl-head-thumb {
  flex-shrink: 0;
  width: 48px;
  height: 60px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface-muted);
}

.screen-create .tpl-head-text {
  flex: 1;
  min-width: 0;
}

.screen-create .tpl-head-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 22px;
  color: var(--text);
}
.screen-create .tpl-head-title ion-icon {
  flex-shrink: 0;
  font-size: 16px;
  color: var(--accent);
}
.screen-create .tpl-head-title span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.screen-create .tpl-head-sub {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 17px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ✕ that drops the template (44px touch target). */
.screen-create .tpl-head-x {
  position: relative;
  align-self: flex-start;
  background: var(--surface-muted);
  border-radius: 50%;
  color: var(--text-2);
}
.screen-create .tpl-head-x::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}

/* The disclosure sits under the pick buttons before a photo is picked. */
.screen-create .upload-zone .ai-note {
  max-width: 280px;
  margin: var(--s-md) 0 0;
}

/* Photo picked (template): card + one big button instead of the prompt editor. */
.screen-create .ready-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-sm);
  padding: var(--s-sm) var(--s-lg) var(--s-sm);
}

/* Full-screen photo preview (tap anywhere to close). */
.screen-create .photo-preview {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  animation: fadeIn 0.22s ease both;
  cursor: zoom-out;
}
.screen-create .photo-preview:focus {
  outline: none; /* focus moves onto the dialog when it opens */
}
.screen-create .photo-preview.out {
  animation: createFadeOut 0.2s ease both;
}
.screen-create .photo-preview img {
  width: 100%;
  height: 80%;
  object-fit: contain;
}

@keyframes createFadeOut {
  to {
    opacity: 0;
  }
}

/* Short screens (iPhone SE & co.). */
@media (max-height: 700px) {
  .screen-create .upload-wrap {
    padding-bottom: 104px;
  }
  .screen-create .pick-row {
    margin-top: var(--s-lg);
  }
  .screen-create .pick-btn {
    height: 48px;
  }
  .screen-create .upload-zone.is-template .pick-row {
    margin-top: var(--s-md);
  }
  .screen-create .ready-area .btn {
    height: 52px;
  }
}

/* ---------- Generating overlay (shared: create + paid) ---------- */

.gen-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-lg);
  pointer-events: none;
}

.gen-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.gen-logo {
  width: 132px;
  height: 132px;
  animation: genSquash 1.46s infinite;
  will-change: transform;
}
.gen-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gen-wordmark {
  margin-top: var(--s-sm);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.8px;
  line-height: 1.15;
  color: var(--charcoal);
}

.gen-caption {
  margin: var(--s-xs) 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--charcoal-soft);
  opacity: 0.7;
  animation: genCaptionIn 0.38s ease-out 0.4s both;
}
.gen-caption.swap {
  animation: genCaptionIn 0.38s ease-out both;
}

/* Indeterminate progress bar (no fake percentage) + time hints, shown while
   an image is being generated (.is-generating). */
.gen-progress {
  position: relative;
  width: 148px;
  height: 4px;
  margin-top: var(--s-sm);
  border-radius: 2px;
  overflow: hidden;
  background: rgba(123, 92, 250, 0.16);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.gen-progress span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  border-radius: 2px;
  background: var(--accent);
  transform: translateX(-100%);
}
.gen-overlay.is-generating .gen-progress {
  opacity: 1;
}
.gen-overlay.is-generating .gen-progress span {
  animation: genProgress 1.5s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

.gen-hint {
  max-width: 250px;
  max-height: 0;
  margin: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--charcoal-soft);
  opacity: 0;
  text-wrap: balance;
  transition: max-height 0.35s var(--ease-out), margin 0.35s var(--ease-out), opacity 0.35s ease 0.1s;
}
.gen-hint.is-on {
  max-height: 34px;
  margin-top: var(--s-xs);
  opacity: 0.62;
}
.gen-hint-browse.is-on {
  margin-top: 4px;
}

@keyframes genProgress {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(250%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gen-overlay.is-generating .gen-progress span {
    animation-duration: 3s;
  }
}

/* Light frosted tint over the blurred photo (the app's BlurView tint="light"). */
.gen-tint {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(250, 247, 244, 0.5);
  animation: fadeIn 0.45s ease both;
}

.gen-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(22px) saturate(1.15);
  transform: scale(1.18);
}

/* Squash and stretch, same beats as the app: 480ms stretch up, 380ms squash,
   340ms settle with a little overshoot, 260ms rest. */
@keyframes genSquash {
  0% {
    transform: scale(1, 1);
    animation-timing-function: cubic-bezier(0, 0, 0.58, 1);
  }
  32.877% {
    transform: scale(0.88, 1.16);
    animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
  }
  58.904% {
    transform: scale(1.07, 0.94);
    animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  82.192%,
  100% {
    transform: scale(1, 1);
  }
}

@keyframes genCaptionIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 0.7;
    transform: none;
  }
}

/* ---------- Motion polish ---------- */

/* The picked photo settles in (scale + fade) and its controls rise under it. */
.screen-create[data-phase='ready'] .photo-card,
.screen-create[data-phase='prompt'] .photo-card {
  animation: createPhotoIn 0.42s var(--ease-out) both;
}
.screen-create[data-phase='ready'] .ready-area,
.screen-create[data-phase='prompt'] .prompt-area {
  animation: createRise 0.4s var(--ease-out) 0.04s both;
}
@keyframes createPhotoIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateZ(0);
  }
}
@keyframes createRise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* The pick buttons are <label>s for the file inputs: press them like buttons. */
.screen-create .pick-btn {
  transition: transform 0.35s var(--spring), background-color 0.2s ease, opacity 0.2s ease;
}
.screen-create .pick-btn:active {
  transform: scale(0.96);
  transition-duration: 0.1s;
}
/* Idea chips press through onPress (scale); tint them too while held. */
.screen-create .idea-chip.is-pressed {
  background: var(--accent-tint);
}

@media (prefers-reduced-motion: reduce) {
  .screen-create[data-phase] .photo-card,
  .screen-create[data-phase] .ready-area,
  .screen-create[data-phase] .prompt-area {
    animation: none;
  }
}

/* While a prank is generating the header's "Get Pro" pill steps aside (create.js
   toggles .is-generating on the screen). */
.screen-create .app-header .pro-pill {
  transition: opacity 0.2s ease;
}
.screen-create.is-generating .app-header .pro-pill {
  opacity: 0;
  pointer-events: none;
}
