﻿/* ==========================================================================
   swapora.space — "Crush" theme
   Mobile-first, pink / peach / lilac, hearts & soft motion. Light only.
   Works with the original app.js DOM contract (same IDs & state classes).
   ========================================================================== */

:root {
  --bg: #fff4f6;
  --bg2: #ffe1ea;
  --ink: #2b0f1f;
  --muted: #8d5d72;
  --card: rgba(255, 255, 255, .72);
  --card-solid: #ffffff;
  --soft: #fff0f4;
  --line: rgba(214, 72, 125, .16);
  --line-strong: rgba(214, 72, 125, .34);
  --pink: #ff3d7f;
  --rose: #ff6b9a;
  --peach: #ff9a6b;
  --lilac: #b18cff;
  --grad: linear-gradient(135deg, #ff3d7f 0%, #ff6b9a 48%, #ff9a6b 100%);
  --shadow: 0 24px 60px -28px rgba(255, 61, 127, .45), 0 2px 8px rgba(43, 15, 31, .05);
  --blob1: #ffb3c9;
  --blob2: #ffd5bd;
  --blob3: #e4d3ff;
  --heart-float: rgba(255, 61, 127, .16);
  --danger-bg: rgba(255, 64, 96, .1);
  --danger: #c8213f;
  --radius-xl: 28px;
  --radius-lg: 22px;
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .4s, color .4s;
}
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 700; letter-spacing: -.02em; }
:focus-visible { outline: 3px solid var(--rose); outline-offset: 3px; border-radius: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.only-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
  .only-mouse { display: inline; }
  .only-touch { display: none; }
}

/* ---------- Animated background ---------- */
.sky {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: radial-gradient(120% 80% at 50% -10%, var(--bg2), var(--bg) 62%);
  transition: background .4s;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: .7;
  animation: drift 20s ease-in-out infinite alternate;
}
.b1 { width: 55vmax; height: 55vmax; background: var(--blob1); top: -22vmax; left: -18vmax; }
.b2 { width: 45vmax; height: 45vmax; background: var(--blob2); bottom: -20vmax; right: -14vmax; animation-delay: -7s; }
.b3 { width: 34vmax; height: 34vmax; background: var(--blob3); top: 38%; left: 58%; animation-delay: -13s; opacity: .5; }
@keyframes drift { to { transform: translate3d(6vmax, 4vmax, 0) scale(1.14); } }

.float-hearts span {
  position: absolute; bottom: -60px; left: var(--x);
  font-size: var(--s); line-height: 1; color: var(--heart-float);
  animation: rise var(--d) linear var(--delay) infinite;
}
@keyframes rise {
  0%   { transform: translate3d(0, 0, 0) rotate(-12deg); opacity: 0; }
  10%  { opacity: 1; }
  50%  { transform: translate3d(var(--drift), -55vh, 0) rotate(12deg); }
  90%  { opacity: 1; }
  100% { transform: translate3d(0, -115vh, 0) rotate(-8deg); opacity: 0; }
}

/* ---------- Shell & top bar ---------- */
.page-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 0 14px env(safe-area-inset-bottom);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 2px 6px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center;
  background: var(--grad); box-shadow: 0 10px 22px -8px rgba(255, 61, 127, .7);
}
.brand-mark svg { width: 20px; fill: #fff; animation: beat 2.4s ease-in-out infinite; }
.brand-name { font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 700; font-size: 1.3rem; letter-spacing: -.02em; }
.brand-dot { color: var(--muted); font-style: italic; font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.server-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); backdrop-filter: blur(12px);
  font-size: .75rem; font-weight: 700; color: var(--muted);
}
.server-pill i { width: 8px; height: 8px; border-radius: 50%; background: #f5b13d; animation: blink 1.2s infinite; }
.server-pill.ready i { background: #27c98a; animation: none; box-shadow: 0 0 0 4px rgba(39, 201, 138, .18); }
.server-pill.error i { background: #ff4d6a; animation: none; }
@keyframes blink { 50% { opacity: .3; } }

.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); backdrop-filter: blur(12px);
  display: grid; place-items: center; font-size: 1.05rem; line-height: 1;
  transition: transform .3s;
}
.theme-toggle:active { transform: rotate(-30deg) scale(.92); }

/* ---------- Intro ---------- */
.intro { text-align: center; padding: 18px 4px 14px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 12px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--pink);
}
.eyebrow-heart { display: inline-block; animation: beat 1.6s infinite; }
.intro h1 {
  margin: 0;
  font-size: clamp(2.3rem, 10.5vw, 4.6rem);
  line-height: .98;
  background: linear-gradient(95deg, var(--ink) 10%, var(--pink) 55%, var(--peach) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  padding-bottom: .06em;
}
.intro-copy { margin: 12px auto 0; max-width: 36ch; color: var(--muted); font-size: .95rem; line-height: 1.5; }
.steps-mini {
  list-style: none; margin: 16px 0 0; padding: 0;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .78rem; font-weight: 700; color: var(--muted);
}
.steps-mini li { display: inline-flex; align-items: center; gap: 6px; }
.steps-mini b {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card-solid); border: 1px solid var(--line-strong); color: var(--pink); font-size: .68rem;
}
.steps-sep { color: var(--rose); opacity: .6; font-size: .7rem; }

/* ---------- Mode switch (sliding pill) ---------- */
.mode-switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  width: min(100%, 280px); margin: 6px auto 16px; padding: 5px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.mode-switch::before {
  content: ""; position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px);
  border-radius: 999px; background: var(--grad);
  box-shadow: 0 8px 20px -8px rgba(255, 61, 127, .8);
  transition: transform .45s cubic-bezier(.3, 1.4, .5, 1);
}
.mode-switch:has(#mode-head.active)::before { transform: translateX(100%); }
.mode-tab {
  position: relative; z-index: 1; height: 36px; border: 0; background: none; border-radius: 999px;
  font-weight: 700; font-size: .84rem; color: var(--muted); transition: color .3s;
}
.mode-tab.active { color: #fff; }
.mode-tab:disabled { cursor: not-allowed; }

/* ---------- Panels ---------- */
.workspace { display: grid; gap: 16px; }
.editor-panel,
.result-panel {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  padding: 18px;
}
.section-heading, .result-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-kicker, .result-kicker {
  font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--pink);
}
.section-heading h2, .result-header h2 { margin: 2px 0 0; font-size: 1.5rem; line-height: 1.1; }
.section-count {
  font-size: .72rem; font-weight: 800; color: var(--muted);
  padding: 6px 10px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line);
}
.section-help { margin: 8px 0 16px; color: var(--muted); font-size: .86rem; line-height: 1.5; }

/* ---------- Upload grid ---------- */
.upload-grid {
  --gap: 14px;
  --head-h: 38px;
  --ar: 1.25; /* drop zone height / width */
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap);
  container-type: inline-size;
}
.upload-field { min-width: 0; }
.field-heading { display: flex; align-items: center; gap: 8px; height: var(--head-h); margin-bottom: 8px; min-width: 0; }
.field-heading > div { min-width: 0; }
.step-badge {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--grad); color: #fff; font-size: .75rem; font-weight: 800;
}
.field-heading h3 { margin: 0; font-size: 1rem; line-height: 1.1; }
.field-heading p { margin: 1px 0 0; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dropzone {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 1 / var(--ar); border-radius: var(--radius-lg);
  border: 2px dashed var(--line-strong);
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .5), transparent 55%),
    var(--soft);
  overflow: hidden; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .3s cubic-bezier(.3, 1.4, .5, 1), border-color .25s, box-shadow .25s, background-color .25s;
}
.dropzone:hover { border-color: var(--rose); transform: translateY(-2px); }
.dropzone:active { transform: scale(.97); }
.dropzone.dragging {
  border-style: solid; border-color: var(--pink); transform: scale(1.03);
  background: color-mix(in srgb, var(--pink) 14%, var(--soft));
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--pink) 18%, transparent);
}
.upload-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.dropzone.has-image { border-style: solid; border-color: var(--pink); box-shadow: 0 14px 30px -14px rgba(255, 61, 127, .7); }
.dropzone.has-image .upload-preview { display: block; animation: pop-in .55s cubic-bezier(.2, 1.4, .4, 1); }
.dropzone.has-image .drop-empty { display: none; }

.drop-empty { display: grid; justify-items: center; gap: 6px; padding: 10px; text-align: center; }
.upload-icon {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 4px;
  background: var(--card-solid); color: var(--pink);
  box-shadow: 0 10px 24px -10px rgba(255, 61, 127, .55);
  animation: bob 3.2s ease-in-out infinite;
}
#target-drop .upload-icon { animation-delay: -1.6s; }
.upload-icon svg { width: 28px; height: 28px; }
.drop-empty strong { font-size: .88rem; }
.drop-empty small { font-size: .7rem; color: var(--muted); }

.replace-label {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: none; padding: 7px 12px; border-radius: 999px; white-space: nowrap;
  background: rgba(30, 6, 20, .55); color: #fff; backdrop-filter: blur(8px);
  font-size: .72rem; font-weight: 700;
}
.has-image .replace-label { display: block; }
.drop-check {
  position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--grad); color: #fff; font-size: .8rem; font-weight: 800;
  box-shadow: 0 6px 14px -4px rgba(255, 61, 127, .8);
  transform: scale(0); transition: transform .45s cubic-bezier(.3, 1.8, .5, 1) .1s;
}
.has-image .drop-check { transform: scale(1); }

.file-name {
  display: block; margin-top: 8px; text-align: center;
  font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Heart that links the two photos — fills up when both are chosen */
.match-heart {
  position: absolute; left: 50%; top: 46%;
  top: calc(var(--head-h) + 8px + (100cqw - var(--gap)) / 2 * var(--ar) / 2);
  transform: translate(-50%, -50%);
  width: 50px; height: 50px; border-radius: 50%; z-index: 2;
  display: grid; place-items: center;
  background: var(--card-solid); border: 1px solid var(--line);
  color: var(--line-strong);
  box-shadow: 0 10px 24px -10px rgba(43, 15, 31, .35);
  transition: color .3s, background .3s, transform .4s cubic-bezier(.3, 1.6, .5, 1);
  pointer-events: none;
}
.match-heart svg { width: 24px; fill: transparent; stroke: currentColor; stroke-width: 2; transition: fill .3s; }
.upload-grid:has(.has-image) .match-heart { color: var(--pink); }
.upload-grid:has(#face-drop.has-image):has(#target-drop.has-image) .match-heart {
  background: var(--grad); border-color: transparent; color: #fff;
  transform: translate(-50%, -50%) scale(1.12);
}
.upload-grid:has(#face-drop.has-image):has(#target-drop.has-image) .match-heart svg { fill: #fff; animation: beat 1.3s ease-in-out infinite; }

/* ---------- Options ---------- */
.prompt-section {
  margin-top: 16px; padding: 12px 14px; border-radius: 18px;
  background: color-mix(in srgb, var(--card-solid) 60%, transparent); border: 1px solid var(--line);
}
.prompt-toggle-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle-box {
  position: relative; flex: none; width: 46px; height: 28px; border-radius: 999px;
  background: var(--line-strong); transition: background .25s;
}
.toggle-box span {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: transform .3s cubic-bezier(.3, 1.5, .5, 1);
}
#extra-toggle:checked + .toggle-box { background: var(--pink); }
#extra-toggle:checked + .toggle-box span { transform: translateX(18px); }
#extra-toggle:focus-visible + .toggle-box { outline: 3px solid var(--rose); outline-offset: 3px; }
.prompt-toggle-text { display: grid; }
.prompt-toggle-text strong { font-size: .9rem; }
.prompt-toggle-text small { font-size: .74rem; color: var(--muted); }
.toggle-chevron { margin-left: auto; color: var(--muted); transition: transform .3s; }
.prompt-section.expanded .toggle-chevron { transform: rotate(180deg); }
#prompt-body .section-help { margin: 12px 0 8px; }
.textarea-wrap { position: relative; }
.textarea-wrap textarea {
  width: 100%; resize: vertical; min-height: 90px;
  padding: 12px 12px 28px; border-radius: 14px;
  border: 1px solid var(--line-strong); background: var(--bg);
  font-size: 16px; /* prevents iOS zoom */ line-height: 1.45;
}
.textarea-wrap textarea:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pink) 18%, transparent); }
#char-count { position: absolute; right: 12px; bottom: 9px; font-size: .7rem; color: var(--muted); }

.foreground-option {
  display: flex; align-items: center; gap: 12px; margin-top: 16px;
  padding: 12px 14px; border-radius: 18px; cursor: pointer;
  background: color-mix(in srgb, var(--card-solid) 60%, transparent); border: 1px solid var(--line);
}
.foreground-option input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  position: relative; width: 46px; height: 28px; border-radius: 999px;
  background: var(--line-strong); cursor: pointer; transition: background .25s;
}
.foreground-option input::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: transform .3s cubic-bezier(.3, 1.5, .5, 1);
}
.foreground-option input:checked { background: var(--pink); }
.foreground-option input:checked::before { transform: translateX(18px); }
.foreground-option > span { display: grid; gap: 1px; }
.foreground-option strong { font-size: .9rem; }
.foreground-option small { font-size: .74rem; color: var(--muted); line-height: 1.35; }

.error-message {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px;
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  font-size: .86rem; font-weight: 600; animation: shake .4s;
}

/* ---------- Action row (sticky on mobile) ---------- */
.action-row {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  margin: 18px -18px -18px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  background: color-mix(in srgb, var(--card-solid) 82%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.action-note { display: none; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); }
.sparkle { color: var(--pink); }

.primary-button {
  position: relative; overflow: hidden; flex: 1;
  height: 58px; padding: 0 24px; border: 0; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--grad); color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: .01em;
  box-shadow: 0 16px 30px -12px rgba(255, 61, 127, .8);
  transition: transform .2s, box-shadow .3s, opacity .3s;
}
.primary-button::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%);
  transform: translateX(-100%); animation: shimmer 2.8s ease-in-out infinite;
}
.primary-button:active:not(:disabled) { transform: scale(.97); }
.primary-button:disabled {
  background: var(--line-strong); color: color-mix(in srgb, var(--ink) 55%, transparent);
  box-shadow: none; cursor: not-allowed;
}
.primary-button:disabled::after { display: none; }
.button-arrow {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .22); font-size: .95rem;
}
.primary-button:not(:disabled) .button-arrow { animation: beat 1.4s ease-in-out infinite; }
.editor-panel:has(#face-drop.has-image):has(#target-drop.has-image) .primary-button:not(:disabled) {
  animation: glow 2.2s ease-in-out infinite;
}

/* ---------- Result ---------- */
.result-header { margin-bottom: 14px; }
.result-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-size: .74rem; font-weight: 800;
  background: var(--soft); color: var(--muted); border: 1px solid var(--line);
}
.result-status.running { color: var(--pink); background: color-mix(in srgb, var(--pink) 12%, var(--soft)); }
.result-status.running::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--pink); animation: blink 1s infinite; }
.result-status.complete { color: #fff; background: var(--grad); border-color: transparent; }

.result-stage {
  position: relative; isolation: isolate; overflow: hidden;
  aspect-ratio: 4 / 5; border-radius: var(--radius-lg);
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--pink) 10%, transparent), transparent 65%),
    var(--soft);
  border: 1px solid var(--line);
}
.result-image {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  animation: reveal 1.2s cubic-bezier(.2, .8, .2, 1);
}

/* Empty state */
.result-empty { display: grid; justify-items: center; gap: 4px; padding: 24px; text-align: center; }
.empty-art { position: relative; width: 170px; height: 120px; margin-bottom: 10px; }
.ea-card {
  position: absolute; top: 10px; width: 76px; height: 96px; border-radius: 16px;
  display: grid; place-items: end center; overflow: hidden;
  background: var(--card-solid); border: 1px solid var(--line);
  box-shadow: 0 14px 30px -14px rgba(43, 15, 31, .35);
  color: color-mix(in srgb, var(--rose) 45%, transparent);
}
.ea-card svg { width: 64px; margin-bottom: -6px; }
.ea-left { left: 6px; transform: rotate(-12deg); animation: sway-l 4s ease-in-out infinite; }
.ea-right { right: 6px; transform: rotate(12deg); animation: sway-r 4s ease-in-out infinite; color: color-mix(in srgb, var(--peach) 55%, transparent); }
.ea-heart {
  position: absolute; left: 50%; top: 42px; margin-left: -24px; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; background: var(--grad); z-index: 2;
  box-shadow: 0 10px 24px -8px rgba(255, 61, 127, .8);
}
.ea-heart svg { width: 24px; fill: #fff; animation: beat 1.4s ease-in-out infinite; }
.result-empty h3 { margin: 4px 0 0; font-size: 1.4rem; line-height: 1.15; }
.result-empty p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; }

/* Working state */
.result-working {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 52px 18px 18px; text-align: center;
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--pink) 16%, transparent), transparent 62%);
}
.working-top {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3;
  display: flex; justify-content: space-between; pointer-events: none;
}
.chip {
  padding: 7px 11px; border-radius: 999px; font-size: .78rem; font-weight: 800;
  background: var(--card-solid); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.game-score { color: var(--pink); }
.game-score.bump { animation: bump .35s cubic-bezier(.3, 1.8, .5, 1); }

.merge { position: relative; width: 220px; height: 130px; flex: none; margin-bottom: 6px; }
.merge-photo {
  position: absolute; top: 50%; width: 92px; height: 92px; border-radius: 50%; overflow: hidden;
  border: 4px solid var(--card-solid); background: var(--grad);
  box-shadow: 0 14px 30px -12px rgba(255, 61, 127, .7);
}
.merge-photo img { width: 100%; height: 100%; object-fit: cover; }
.merge-photo img:not([src]) { display: none; }
.merge-a { left: 0; animation: swing-a 2.6s ease-in-out infinite; }
.merge-b { right: 0; animation: swing-b 2.6s ease-in-out infinite; background: linear-gradient(135deg, var(--peach), var(--lilac)); }
.merge-core {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--grad);
  box-shadow: 0 10px 24px -6px rgba(255, 61, 127, .9);
}
.merge-core svg { width: 26px; fill: #fff; animation: beat 1.2s ease-in-out infinite; }
.merge-core::before,
.merge-core::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--pink); animation: ripple 2.4s ease-out infinite;
}
.merge-core::after { animation-delay: 1.2s; }

#working-title { margin: 0; font-size: 1.45rem; line-height: 1.15; }
#working-copy { margin: 0; max-width: 30ch; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.progress-track {
  width: min(260px, 82%); height: 8px; margin-top: 6px; border-radius: 999px; overflow: hidden;
  background: var(--line);
}
.progress-track span {
  position: relative; display: block; height: 100%; width: 6%; border-radius: inherit;
  background: var(--grad); overflow: hidden; transition: width .5s ease;
}
.progress-track span::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .6), transparent);
  animation: shimmer 1.4s linear infinite; transform: translateX(-100%);
}
.working-tip {
  margin: 6px 0 0; min-height: 1.3em; font-size: .8rem; font-weight: 700; color: var(--pink);
  transition: opacity .35s, transform .35s;
}
.working-tip.swap { opacity: 0; transform: translateY(6px); }

/* Mini game: catch hearts while waiting */
.heart-game { position: absolute; inset: 0; z-index: 4; overflow: hidden; pointer-events: none; }
.g-heart {
  position: absolute; bottom: -56px; left: var(--x);
  width: var(--size); height: var(--size); padding: 0; border: 0; background: none;
  color: var(--pink); pointer-events: auto; touch-action: manipulation;
  filter: drop-shadow(0 6px 10px rgba(255, 61, 127, .4));
  animation: g-rise var(--dur) linear forwards;
}
.g-heart::before { content: ""; position: absolute; inset: -12px; } /* bigger tap target */
.g-heart svg { width: 100%; height: 100%; fill: currentColor; }
.g-heart.gold { color: #ffb21e; filter: drop-shadow(0 0 10px rgba(255, 190, 40, .9)); }
.g-heart.pop svg { animation: g-pop .35s ease-out forwards; }
@keyframes g-rise {
  0%   { transform: translate(-50%, 0) scale(.5); opacity: 0; }
  8%   { transform: translate(-50%, -6%) scale(1); opacity: 1; }
  30%  { transform: translate(calc(-50% + var(--sway)), calc(var(--h) * -.3)); }
  60%  { transform: translate(calc(-50% - var(--sway)), calc(var(--h) * -.62)); }
  100% { transform: translate(-50%, calc(var(--h) * -1 - 70px)); opacity: .9; }
}
@keyframes g-pop { to { transform: scale(1.9); opacity: 0; } }
.g-plus {
  position: absolute; transform: translate(-50%, -50%); pointer-events: none;
  font-weight: 800; font-size: 1rem; color: var(--pink);
  animation: plus .8s ease-out forwards;
}
.g-plus.gold { color: #f0a000; font-size: 1.2rem; }
@keyframes plus { to { transform: translate(-50%, -190%); opacity: 0; } }

/* Celebration burst */
.burst { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.b-p {
  position: absolute; left: 50%; top: 50%; line-height: 1;
  font-size: var(--fs); color: var(--c);
  animation: burst 1.3s cubic-bezier(.15, .8, .3, 1) forwards;
}
@keyframes burst {
  0%   { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--r)) scale(1); opacity: 0; }
}

.result-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
#result-caption { font-size: .82rem; color: var(--muted); line-height: 1.4; }
.download-button {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 20px; border-radius: 999px;
  background: var(--ink); color: var(--bg); text-decoration: none; font-weight: 800; font-size: .92rem;
  animation: pop-in .5s cubic-bezier(.2, 1.4, .4, 1);
}
.download-button:active { transform: scale(.96); }

/* ---------- Toast & footer ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: calc(100% - 32px); padding: 13px 20px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: .9rem; text-align: center;
  box-shadow: 0 18px 40px -12px rgba(43, 15, 31, .5);
  transform: translate(-50%, 180%); opacity: 0; visibility: hidden;
  transition: transform .5s cubic-bezier(.2, 1.4, .4, 1), opacity .3s, visibility .5s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .5s cubic-bezier(.2, 1.4, .4, 1), opacity .3s; }

.footer {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 30px 0 36px; font-size: .74rem; color: var(--muted); letter-spacing: .04em;
}
.footer b { color: var(--pink); }

/* ---------- Keyframes ---------- */
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes pop-in { from { transform: scale(.86); opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.25); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes glow { 50% { box-shadow: 0 16px 44px -6px rgba(255, 61, 127, .95); } }
@keyframes ripple { from { transform: scale(1); opacity: .7; } to { transform: scale(2.6); opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes swing-a {
  0%, 100% { transform: translateY(-50%) translateX(0) rotate(-8deg); }
  50% { transform: translateY(-50%) translateX(24px) rotate(4deg); }
}
@keyframes swing-b {
  0%, 100% { transform: translateY(-50%) translateX(0) rotate(8deg); }
  50% { transform: translateY(-50%) translateX(-24px) rotate(-4deg); }
}
@keyframes sway-l { 50% { transform: rotate(-6deg) translate(6px, -4px); } }
@keyframes sway-r { 50% { transform: rotate(6deg) translate(-6px, -4px); } }
@keyframes reveal {
  from { clip-path: circle(0% at 50% 50%); filter: blur(14px) saturate(1.6); transform: scale(1.06); }
  to   { clip-path: circle(75% at 50% 50%); filter: none; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 380px) {
  .page-shell { padding-left: 10px; padding-right: 10px; }
  .server-pill span { display: none; }
  .server-pill { padding: 0 11px; }
  .upload-grid { --gap: 10px; }
  .editor-panel, .result-panel { padding: 14px; }
  .action-row { margin: 16px -14px -14px; padding-left: 14px; padding-right: 14px; }
  .merge { transform: scale(.88); }
}

@media (min-width: 960px) {
  .page-shell { padding: 0 24px; }
  .intro { padding: 34px 0 18px; }
  .workspace { grid-template-columns: minmax(0, 1.08fr) minmax(0, .92fr); gap: 22px; align-items: start; }
  .result-panel { position: sticky; top: 20px; }
  .editor-panel, .result-panel { padding: 26px; }
  .upload-grid { --gap: 22px; --ar: 1; }
  .action-row {
    position: static; margin: 22px 0 0; padding: 0;
    background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
    justify-content: space-between;
  }
  .action-note { display: flex; }
  .primary-button { flex: none; padding: 0 30px; }
  .footer { flex-direction: row; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  html { scroll-behavior: auto; }
}

/* Compact upload screen and modal result. */
.page-shell { width: min(760px, 100%); }
.workspace { grid-template-columns: minmax(0, 1fr); }
.section-heading h2 { font-size: 1.3rem; }
.section-help { margin-bottom: 12px; }
.upload-grid { --ar: 1; }
.action-note { display: none; }
.action-row .primary-button { flex: 1; }
.footer { margin-top: 12px; }

/* Processing and results replace the upload card in the same workspace. */
.editor-panel:not([hidden]), .result-panel:not([hidden]) {
  animation: screen-enter .3s ease-out;
}
@keyframes screen-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.workspace > .result-panel { position: relative; top: auto; }
.result-controls { display: flex; align-items: center; gap: 10px; }
.result-close {
  width: 40px; height: 40px; flex-shrink: 0; border: 1px solid var(--line);
  border-radius: 50%; background: var(--soft); color: var(--ink); font-size: 25px;
}
.result-header { flex-direction: row-reverse; }
.result-controls { flex-direction: row-reverse; }
.workspace > .result-panel .result-stage {
  aspect-ratio: auto; height: min(60dvh, 540px); min-height: 280px;
}
.workspace > .result-panel .result-footer { gap: 12px; }
@media (max-height: 650px) {
  .workspace > .result-panel .result-stage { min-height: 230px; height: 52dvh; }
  .result-working { gap: 4px; padding-top: 40px; }
  .result-working .merge { transform: scale(.75); margin: -15px 0; }
}
@media (min-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .upload-grid { --ar: 1.15; }
}
@media (prefers-reduced-motion: reduce) {
  .editor-panel:not([hidden]), .result-panel:not([hidden]) { animation: none; }
}

/* Mobile home: balanced spacing with a quiet, centered upload card. */
@media (max-width: 767px) {
  .page-shell { min-height: 100svh; display: flex; flex-direction: column; }
  .topbar { flex-shrink: 0; padding-bottom: 12px; }
  .page-shell > main { flex: 1; min-width: 0; }
  .page-shell > main:has(#result-panel[hidden]) {
    display: flex; flex-direction: column; justify-content: flex-start;
    padding: clamp(24px, 5svh, 44px) 0 20px; gap: 16px;
  }
  main:has(#result-panel[hidden]) .mode-switch { margin: 0 auto; flex-shrink: 0; }
  .editor-panel > .section-help { display: none; }
  .editor-panel .section-heading { margin-bottom: 16px; }
  .editor-panel .section-heading h2 { font-size: 1.2rem; }
  .file-name { display: none; }
  .upload-grid { --ar: 1.12; }
  .match-heart { width: 42px; height: 42px; }
  .editor-panel .action-row { margin-top: 18px; }
  .editor-panel .primary-button { height: 54px; font-size: 1rem; }
  .footer { flex-shrink: 0; margin-top: 0; padding: 12px 0 18px; font-size: .7rem; }
  .footer > span:last-child { display: none; }
}
@media (max-width: 767px) and (max-height: 650px) {
  .page-shell > main:has(#result-panel[hidden]) { padding: 8px 0; gap: 12px; }
  .upload-grid { --ar: .95; }
  .footer { padding: 8px 0 12px; }
}

.result-close:disabled { opacity: .35; cursor: not-allowed; }

.queue-live { display: flex; align-items: center; justify-content: center; gap: 7px; margin: -6px 0 14px; font-size: .73rem; font-weight: 600; color: var(--muted); }
.queue-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--pink); }
@media (max-width: 767px) {
  main:has(#result-panel[hidden]) .queue-live { margin: -8px 0 -2px; }
}

.result-close { display: grid; place-items: center; padding: 0; line-height: 1; }
.result-close svg { width: 21px; height: 21px; display: block; }

.head-access-note { margin: -4px auto 14px; padding: 10px 14px; max-width: 560px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: .78rem; line-height: 1.5; text-align: center; }
@media (max-width: 767px) { main:has(#result-panel[hidden]) .head-access-note { margin: -4px 0 0; } }

html[data-swap-mode="face"] .queue-live,
html[data-swap-mode="face"] .working-top,
html[data-swap-mode="face"] #working-timer,
html[data-swap-mode="face"] #result-status:not(.complete),
html[data-swap-mode="face"] #working-tip { display: none; }
.queue-live { flex-wrap: wrap; row-gap: 3px; }
.head-eta-text { flex-basis: 100%; text-align: center; font-size: .72rem; font-weight: 500; }
.head-eta-text:empty { display: none; }
.result-working .result-eta { color: var(--pink); font-size: .8rem; font-weight: 700; margin: 2px 0; }
