* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f5f8;
  color: #211f2b;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid #e6e3ee;
  background: #fff;
}
.brand { font-weight: 700; font-size: 15px; }
.badge {
  font-size: 11px;
  color: #7a5cff;
  background: #f1ecff;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
}

.col.left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #fff;
  border: 1px solid #e6e3ee;
  border-radius: 14px;
  padding: 18px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #5c5670;
  margin-bottom: 6px;
}

.dual-row {
  display: flex;
  gap: 12px;
}
.dual-col {
  flex: 1;
  min-width: 0;
}

.advanced-field summary {
  font-size: 12px;
  font-weight: 600;
  color: #5c5670;
  cursor: pointer;
  list-style: none;
}
.advanced-field summary::-webkit-details-marker { display: none; }
.advanced-field summary::before { content: "▸ "; color: #b3a6ea; }
.advanced-field[open] summary::before { content: "▾ "; }
.advanced-field summary ~ * { margin-top: 8px; }

.field select {
  width: 100%;
  border: 1px solid #e0dcec;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12.5px;
  color: #5c5670;
  background: #fff;
}
.field select:focus { outline: none; border-color: #a894f0; }

.dropzone {
  position: relative;
  border: 1.5px dashed #d6d1e6;
  border-radius: 10px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #fbfaff;
  overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover { border-color: #a894f0; background: #f5f2ff; }
.dz-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #8f88a8;
  font-size: 12.5px;
}
.dz-empty[hidden] { display: none; }
.dz-icon { font-size: 22px; color: #b3a6ea; }
.preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

textarea {
  width: 100%;
  border: 1px solid #e0dcec;
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
textarea:focus { outline: none; border-color: #a894f0; }

.btn-primary {
  background: #7a5cff;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn-primary:hover:not(:disabled) { background: #6947f0; }
.btn-primary:disabled { background: #d9d4ea; cursor: not-allowed; }

/* --- middle column: masonry of BLOCK cards ---
   Real column-balancing masonry (JS-driven, see app.js): each new block is
   placed into whichever column is currently shortest, measured by actual
   rendered height (not just image aspect ratio, since a block card's height
   depends on its prompt length + how many results it has). */

.col.middle { min-width: 0; }

.block-masonry {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.block-masonry-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.gallery-empty-hint {
  color: #a29bb8;
  font-size: 13px;
  text-align: center;
  margin-top: 60px;
}
.gallery-empty-hint[hidden] { display: none; }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #ece8f7;
  border-top-color: #7a5cff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.step-caption { color: #5c5670; font-size: 12.5px; font-weight: 600; }
.error-text { color: #d0455c; font-size: 11.5px; }

/* --- block card: one materialized creative (archival creative-image badge +
   editable prompt + current product image + generate) plus a grid of every
   result it has produced so far. --- */

.block-card {
  position: relative;
  background: #fff;
  border: 1px solid #e6e3ee;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Archival only — deliberately small and in the corner, spatially separate
   from the product-image row so it never reads as an active input. */
.creative-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid #e6e3ee;
  opacity: 0.85;
}

/* Composite "flomo-style" input: the current product image(s) and the prompt
   text live inside ONE bordered box, so they read as "one thing that acts
   together" — unlike the creative-image badge, which sits outside entirely
   because it's archival, not part of what actually gets sent to generate. */
.prompt-composer {
  border: 1px solid #e0dcec;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.prompt-composer:focus-within { border-color: #a894f0; }

.composer-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.composer-thumb {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e6e3ee;
  flex-shrink: 0;
}
.composer-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.composer-thumb .remove-btn {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.composer-add-btn {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1.5px dashed #d6d1e6;
  background: #fbfaff;
  color: #b3a6ea;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.composer-add-btn:hover { border-color: #a894f0; background: #f5f2ff; }

/* Collapsed by default with a capped height + a fade/"展开" hint whenever the
   prompt is longer than that — otherwise a long LLM-written prompt looks like
   the two or three lines you can see, and nothing tells you there's more
   below. Focusing (or clicking the hint) expands to a generous cap so editing
   is comfortable; blurring collapses it back. Short prompts never show the
   hint at all, so this costs nothing visually for the common case. */
.prompt-shell { position: relative; }
.prompt-composer .block-prompt {
  width: 100%;
  height: 110px; /* a <textarea> never grows to fit content on its own — JS
                    sets an explicit inline height when expanded (see
                    wirePromptShell in app.js) and clears it to fall back to
                    this fixed collapsed height. */
  overflow-y: hidden;
  border: none;
  padding: 4px 2px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.55;
  resize: none;
}
.prompt-composer .block-prompt:focus { outline: none; }
.prompt-shell.expanded .block-prompt { overflow-y: auto; }

.fade-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, #fff 75%);
  pointer-events: none;
}
.fade-hint span {
  pointer-events: auto;
  background: #fff;
  border: 1px solid #e0dcec;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 10.5px;
  font-weight: 600;
  color: #7a5cff;
  cursor: pointer;
}
.prompt-shell.expanded .fade-hint,
.prompt-shell.no-overflow .fade-hint {
  display: none;
}

.generate-btn { background: #7a5cff; }
.generate-btn:hover:not(:disabled) { background: #6947f0; }

/* Results masonry — inner, per-block: two columns, real image aspect ratio
   (no cropping), same "shortest column" placement logic as the outer block
   masonry (see app.js), just scoped to this one block's own results. */
.block-results {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed #eee;
}
.result-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-item {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e6e3ee;
  cursor: pointer;
  position: relative;
  background: #fbfaff;
}
.result-item img { width: 100%; display: block; }
.result-item:hover { box-shadow: 0 3px 10px rgba(90, 70, 150, 0.15); }
.result-item.pending {
  cursor: default;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-item .modified-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  background: #c9760a;
  color: #fff;
  font-size: 8.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  line-height: 1.4;
}
.result-item .error-text {
  padding: 6px;
  text-align: center;
  font-size: 9.5px;
}

/* --- modal: click a gallery item to see the image + its own log side by side --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: 14px;
  width: min(1100px, 100%);
  height: 90vh;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  overflow: hidden;
  position: relative;
}
@media (max-width: 760px) {
  .modal { grid-template-columns: 1fr; grid-template-rows: 40vh 1fr; }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.modal-image-pane {
  background: #17141f;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.modal-image-pane img { max-width: 100%; max-height: 100%; object-fit: contain; }

.modal-right {
  height: 100%;
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.action-card {
  background: #fbfaff;
  border: 1px solid #e6e3ee;
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Download/Compare act on the result, not on the Modify function — kept
   outside .action-card so they don't read as part of it. */
.modal-secondary-actions { margin-top: -6px; }

.row-2 { display: flex; gap: 8px; }
.row-2 > select {
  flex: 1;
  border: 1px solid #e0dcec;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12.5px;
  color: #5c5670;
  background: #fff;
}
.row-2 > select:focus { outline: none; border-color: #a894f0; }

.btn-action {
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  width: 100%;
}
.modify-btn { background: #7a5cff; }
.modify-btn:hover:not(:disabled) { background: #6947f0; }
.btn-action:disabled { background: #d9d4ea; cursor: not-allowed; }

.btn-secondary {
  flex: 1;
  border: 1px solid #e0dcec;
  border-radius: 8px;
  padding: 9px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: #5c5670;
  background: #fff;
}
.btn-secondary:hover { border-color: #a894f0; background: #f5f2ff; }

.result-info summary { margin-bottom: 0; }
.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  font-size: 12px;
}
.info-grid dt { color: #8f88a8; font-weight: 600; }
.info-grid dd { margin: 0; color: #3a3650; word-break: break-word; white-space: pre-wrap; }

.compare-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 110;
}
.compare-overlay[hidden] { display: none; }
.compare-modal {
  background: #fff;
  border-radius: 14px;
  width: min(1100px, 100%);
  max-height: 90vh;
  padding: 20px;
  position: relative;
  overflow: auto;
}
.compare-panes { display: flex; gap: 16px; }
.compare-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.compare-label { font-size: 12px; font-weight: 600; color: #5c5670; }
.compare-pane img { width: 100%; border-radius: 8px; border: 1px solid #e6e3ee; display: block; }
@media (max-width: 760px) {
  .compare-panes { flex-direction: column; }
}
