/* ═══════════════════════════════════════════════
   MORPHOME — preset.css v3

   Visual sync with generate.html. The .upload-card pattern (same
   class names) is cloned into this file rather than imported from
   generate.css — preset.html stays self-contained, but the look is
   pixel-identical to Generate. If we later refactor generate.css,
   we update both files; the small duplication is the price of
   keeping the two pages independent.

   Earlier preset.css versions (v1, v2) used .pu-slot tiles; that's
   gone. Multi-slot pre­sets (none in production yet) get a small
   .pu-multi-slots grid still defined below, but for input_slots==1
   we use the full Generate-style upload card.
   ═══════════════════════════════════════════════ */

/* HTML's `hidden` attribute must win over any flex/grid display rule. */
[hidden] { display: none !important; }

/* ── Glass surface (identical to generate.css's .glass) ── */
.glass {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, .75);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
}

/* ── Page layout ── */
.preset-stage {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px var(--page-pad) 80px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.btn-back {
  font: 500 13px 'DM Sans', sans-serif;
  color: rgba(255, 255, 255, .82);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  transition: .18s ease;
}
.btn-back:hover {
  background: rgba(255, 255, 255, .14);
  color: #fff;
}

/* ── Header card ── */
.preset-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 28px;
  align-items: center;
  padding: 22px 26px;
}
/* Preset thumbnail — anchors the hero visually and previews the result
   the user is about to generate. Fixed 4:3 ratio so all preset pages
   line up regardless of source image proportions; cover-fit accepts
   3:2 / 5:4 / video sources without distortion. */
.ph-media {
  width: 220px;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(53, 96, 240, .04);
  box-shadow: 0 4px 18px -8px rgba(0, 0, 0, .12);
}
.ph-media img,
.ph-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ph-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ph-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  width: fit-content;
}
.ph-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.ph-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  max-width: 620px;
}
.ph-meta { display: flex; gap: 18px; flex-shrink: 0; }
.ph-meta-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 84px;
  padding: 8px 14px;
  background: rgba(53, 96, 240, .04);
  border-radius: 12px;
  border: 1px solid rgba(53, 96, 240, .07);
}
.ph-meta-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.ph-meta-value { font-size: 14px; font-weight: 600; color: var(--text); }

/* ════════════════════════════════════════════════
   Upload card — cloned from generate.css lines 46-282.
   Comments preserved so future maintainers see the rationale.
   ════════════════════════════════════════════════ */

.upload-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: 420px;
  border-radius: 16px;
  border: 2px dashed rgba(53, 96, 240, .22);
  background: linear-gradient(160deg, #f8faff 0%, #f3f0ff 100%);
  position: relative;
  padding: 40px 24px 32px;
  transition: border-color .2s, background .2s;
  overflow: hidden;
}

/* Default upload state: clickable + glow */
.upload-card.is-upload { cursor: pointer; }
.upload-card.is-upload::before {
  content: '';
  position: absolute;
  top: -60px; left: -60px;
  width: 240px; height: 240px;
  border-radius: 999px;
  background: rgba(104, 64, 245, .07);
  filter: blur(16px);
  pointer-events: none;
}
.upload-card.is-upload:hover {
  border-color: rgba(53, 96, 240, .5);
  background: linear-gradient(160deg, #f5f8ff 0%, #ede8ff 100%);
}

/* Progress state: solid border */
.upload-card.is-progress {
  border: 1px solid rgba(53, 96, 240, .16);
  cursor: default;
}

/* Result state: cleaner surface so the image reads well */
.upload-card.is-result {
  border: 1px solid rgba(53, 96, 240, .12);
  background: linear-gradient(160deg, #fcfdff 0%, #f7f4ff 100%);
  cursor: default;
  padding: 24px;
}

/* Error state */
.upload-card.is-error {
  border: 2px dashed rgba(245, 158, 11, .35);
  background: linear-gradient(160deg, #fff8ec 0%, #fef3e0 100%);
  cursor: default;
}

/* Analyzing state: pulsing soft-blue glow.
   Triggers between "user dropped a file" and "classifier returned". */
.upload-card.is-analyzing {
  border: 1px solid rgba(53, 96, 240, .4);
  background: linear-gradient(160deg, #f8faff 0%, #f0eeff 100%);
  cursor: default;
  animation: morphome-card-pulse 1.6s ease-in-out infinite;
}
@keyframes morphome-card-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(53, 96, 240, .04), 0 0 24px 2px rgba(53, 96, 240, .04); }
  50%      { box-shadow: 0 0 0 0 rgba(53, 96, 240, .18), 0 0 24px 8px rgba(53, 96, 240, .18); }
}

/* Ready state: image loaded + classified, awaiting Generate click. */
.upload-card.is-ready {
  border: 1px solid rgba(53, 96, 240, .5);
  background: linear-gradient(160deg, #fbfcff 0%, #f5f3ff 100%);
  cursor: default;
}

/* Generating state: flowing gradient sweep on the border.
   The card "border" is transparent; the gradient is the background
   with background-clip:border-box. Animates background-position so
   the gradient sweeps across — visual "something's happening" cue. */
.upload-card.is-generating {
  border: 1px solid transparent;
  background:
    linear-gradient(160deg, #f8faff 0%, #f3f0ff 100%) padding-box,
    linear-gradient(
      90deg,
      rgba(53, 96, 240, .15)  0%,
      rgba(53, 96, 240, .7)  25%,
      rgba(104, 64, 245, .7) 50%,
      rgba(53, 96, 240, .7)  75%,
      rgba(53, 96, 240, .15) 100%
    ) border-box;
  background-size: 100% 100%, 300% 100%;
  cursor: default;
  animation: morphome-border-flow 3s linear infinite;
}
@keyframes morphome-border-flow {
  from { background-position: 0% 0%, 0% 0%; }
  to   { background-position: 0% 0%, -300% 0%; }
}

.upload-state { width: 100%; display: flex; justify-content: center; }
.upload-state[hidden] { display: none !important; }

.upload-content {
  position: relative;
  z-index: 1;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.upload-icon {
  width: 58px; height: 58px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 26px;
  box-shadow: 0 10px 28px rgba(53, 96, 240, .3);
  transition: transform .2s;
}
.upload-card.is-upload:hover .upload-icon { transform: translateY(-3px); }

.upload-title { font-size: 24px; font-weight: 500; margin-bottom: 9px; color: var(--text); }
.upload-lead {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
  max-width: 420px;
  margin: 0 auto;
}
.hint-row {
  display: flex;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.hint {
  padding: 5px 11px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

/* ── Progress state ── */
.progress-spinner {
  width: 46px; height: 46px;
  margin-bottom: 18px;
  border: 3px solid rgba(53, 96, 240, .14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: mph-spin .9s linear infinite;
}
@keyframes mph-spin { to { transform: rotate(360deg); } }

.progress-bar-track {
  margin-top: 20px;
  width: 280px;
  max-width: 90%;
  height: 4px;
  background: rgba(53, 96, 240, .12);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px;
  transition: width .5s ease;
}
.progress-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: .04em;
  margin-top: 8px;
}

/* ── Result state ── */
.result-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/*
  result-display is the wrapper for the actual frames/video. Layout
  varies by preset.ui.output_layout:
    - single  → one image at max-height: 60vh
    - grid_2x2 → 2×2 grid of square cells (each labelled with frame name)
    - video   → one <video> at max-height: 60vh
*/
.result-display {
  width: 100%;
  display: grid;
  gap: 10px;
}
.result-display[data-layout="single"]    { grid-template-columns: 1fr; }
.result-display[data-layout="video"]     { grid-template-columns: 1fr; }
.result-display[data-layout="grid_2x2"]  { grid-template-columns: 1fr 1fr; }

.result-cell {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, .04);
}
.result-display[data-layout="single"] .result-cell,
.result-display[data-layout="video"]  .result-cell { aspect-ratio: 16 / 9; }
.result-display[data-layout="grid_2x2"] .result-cell { aspect-ratio: 1 / 1; }

.result-cell img,
.result-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.result-cell .result-cell-label {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: capitalize;
  z-index: 2;
  pointer-events: none;
}

.result-image {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .12);
  display: block;
}
.result-meta {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  letter-spacing: .02em;
}
.result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Buttons (cloned from generate.css) ── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 10px;
  font: 500 13px 'DM Sans', sans-serif;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(53, 96, 240, .3);
  transition: .15s;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(53, 96, 240, .38);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 500 13px 'DM Sans', sans-serif;
  cursor: pointer;
  transition: .15s;
}
.btn-outline:hover {
  border-color: rgba(53, 96, 240, .35);
  color: var(--accent);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  font: 500 13px 'DM Sans', sans-serif;
  cursor: pointer;
  transition: .15s;
}
.btn-ghost:hover {
  color: var(--text);
  background: rgba(17, 24, 39, .04);
}

/* ── Error state ── */
.error-icon {
  width: 58px; height: 58px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 26px;
  box-shadow: 0 10px 28px rgba(245, 158, 11, .3);
}

/* ════════════════════════════════════════════════
   Multi-slot mode (input_slots > 1)
   None of the seeded presets use this yet, but we keep the small
   variant so future presets that need 2-6 inputs (e.g. before/after,
   reference + base) can opt in via JSON.
   ════════════════════════════════════════════════ */

.pu-multi-slots {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 720px;
}
.pu-multi-slots[data-slots="2"] { grid-template-columns: 1fr 1fr; }
.pu-multi-slots[data-slots="3"] { grid-template-columns: 1fr 1fr 1fr; }
.pu-multi-slots[data-slots="4"] { grid-template-columns: 1fr 1fr 1fr 1fr; }
.pu-multi-slots[data-slots="5"],
.pu-multi-slots[data-slots="6"] { grid-template-columns: repeat(3, 1fr); }

.pu-multi-slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  min-height: 0;
  border-radius: 12px;
  border: 1.5px dashed var(--line);
  background: rgba(53, 96, 240, .025);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .2s, background .2s;
}
.pu-multi-slot:hover {
  border-color: var(--accent);
  background: rgba(53, 96, 240, .05);
}
.pu-multi-slot.is-filled {
  border-style: solid;
  border-color: rgba(53, 96, 240, .35);
  background: transparent;
  cursor: default;
}
.pu-multi-slot input[type="file"] { display: none; }
.pu-multi-slot-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  pointer-events: none;
}
.pu-multi-slot-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pu-multi-slot-clear {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  font-size: 12px;
  line-height: 1;
  z-index: 5;
}
.pu-multi-slot.is-filled .pu-multi-slot-clear { display: flex; }

/* ════════════════════════════════════════════════
   Optional notes textarea (only when preset.ui.user_text_label set)
   Notes block is preserved in the markup but kept hidden by default;
   each preset's JSON can opt in via "user_text_label".
   ════════════════════════════════════════════════ */

.pu-text-wrap { display: flex; flex-direction: column; gap: 7px; }
.pu-text-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.pu-text {
  resize: vertical;
  min-height: 56px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font: 400 13px 'DM Sans', sans-serif;
  color: var(--text);
  transition: border-color .18s;
}
.pu-text:focus {
  outline: none;
  border-color: var(--accent);
}

.pu-warn {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(245, 158, 11, .08);
  border: 1px solid rgba(245, 158, 11, .25);
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
}

/* ── Generate button row ── */
.preset-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.generate-btn {
  width: 100%;
  max-width: 380px;
  padding: 14px 22px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font: 600 14px 'DM Sans', sans-serif;
  letter-spacing: .01em;
  box-shadow: 0 8px 22px rgba(53, 96, 240, .28);
  transition: transform .18s, box-shadow .18s, opacity .18s;
}
.generate-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(53, 96, 240, .42);
}
.generate-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Responsive ── */
@media (max-width: 880px) {
  .preset-header { grid-template-columns: 1fr; }
  .ph-meta { flex-wrap: wrap; }
  /* On narrow viewports the thumbnail goes full-width above the text
     instead of being a sidekick. Slightly taller aspect (16:10) reads
     better as a banner than the 4:3 desktop crop. */
  .ph-media { width: 100%; aspect-ratio: 16 / 10; }
}
@media (max-width: 600px) {
  .upload-card { min-height: 320px; padding: 24px 16px; }
  .upload-icon { width: 48px; height: 48px; font-size: 22px; margin-bottom: 12px; }
  .upload-title { font-size: 18px; }
  .result-display[data-layout="grid_2x2"] { grid-template-columns: 1fr; }
  .result-display[data-layout="grid_2x2"] .result-cell { aspect-ratio: 16 / 9; }
}


/* preset-redesign v1 */
.preset-header { grid-template-columns: 1fr 1.05fr; align-items: stretch; gap: 36px; padding: 30px 34px; }
.ph-sub {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 14px; font-weight: 600; color: var(--accent); margin-top: 2px;
}
.ph-sub .ph-sub-spark { color: var(--accent); font-size: 13px; }
.ph-tags { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.ph-tag {
  padding: 7px 15px; border-radius: 999px;
  background: #eef1fb; color: #3a4256;
  font-size: 13px; font-weight: 500;
}
.ph-title { font-size: 30px; }
.ph-desc { max-width: none; }

/* Before / After panel (right column of the hero) */
.ph-ba { display: flex; flex-direction: column; gap: 14px; }
.ba-pair { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ba-card {
  position: relative; border-radius: 18px; overflow: hidden;
  box-shadow: 0 6px 22px -8px rgba(0,0,0,.18); aspect-ratio: 4 / 3;
  background: rgba(53,96,240,.04);
}
.ba-card img, .ba-card video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ba-label {
  position: absolute; top: 12px; left: 12px; padding: 4px 12px;
  border-radius: 8px; background: rgba(20,22,30,.78); color: #fff;
  font-size: 13px; font-weight: 600;
}
.ba-arrow {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 42px; height: 42px; border-radius: 50%; background: #fff;
  box-shadow: 0 4px 16px rgba(53,96,240,.28);
  display: grid; place-items: center; color: var(--accent);
  font-size: 18px; z-index: 3;
}
/* Reuse existing .ph-meta-cell styling, just lay the three cells in a row */
.ph-ba .ph-meta { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }

/* abstract-decor v1 */
.upload-card.is-upload::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .9;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='220' viewBox='0 0 260 220'%3E%3Cg fill='none' stroke='%237b6cf0' stroke-width='1.4' opacity='.4'%3E%3Ccircle cx='70' cy='70' r='42'/%3E%3Ccircle cx='150' cy='150' r='26'/%3E%3Cpath d='M30 170 L70 110 L110 170 Z'/%3E%3Cline x1='120' y1='40' x2='170' y2='40'/%3E%3Cline x1='120' y1='52' x2='150' y2='52'/%3E%3Crect x='160' y='80' width='34' height='34' transform='rotate(18 177 97)'/%3E%3C/g%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='220' viewBox='0 0 240 220'%3E%3Cg fill='none' stroke='%233560f0' stroke-width='1.4' opacity='.34'%3E%3Ccircle cx='170' cy='150' r='48'/%3E%3Cpath d='M40 60 Q90 20 140 60 T240 60' /%3E%3Ccircle cx='60' cy='150' r='16'/%3E%3Cline x1='30' y1='110' x2='30' y2='150'/%3E%3Crect x='90' y='120' width='30' height='30'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: no-repeat, no-repeat;
  background-position: left -10px top 20px, right -10px bottom 14px;
  z-index: 0;
}
.upload-card.is-upload .upload-state { position: relative; z-index: 1; }

@media (max-width: 880px) {
  .preset-header { grid-template-columns: 1fr; }
  .ph-ba .ph-meta { grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 600px) {
  .ph-title { font-size: 24px; }
  .upload-card.is-upload::after { opacity: .25; }
}
/* end preset-redesign v1 */
