:root {
  --bg1: #1a1035; --bg2: #2b1055; --bg3: #0a0618;
  --text: #f4f0ff; --text-dim: #c9c0ea;
  --glass-bg: rgba(255,255,255,0.06);
  --glass-border: rgba(255,255,255,0.14);
  --glass-shadow: 0 8px 40px rgba(0,0,0,0.4);
  --accent1: #ff5e9c; --accent2: #7b5eff; --accent3: #21d4fd;
}
:root[data-theme="light"] {
  --bg1: #e9e4ff; --bg2: #cfe6ff; --bg3: #ffe3f1;
  --text: #241a3f; --text-dim: #5a4c85;
  --glass-bg: rgba(255,255,255,0.45);
  --glass-border: rgba(255,255,255,0.7);
  --glass-shadow: 0 8px 40px rgba(120,90,200,0.18);
  --accent1: #e0397e; --accent2: #6a3ff0; --accent3: #0ea5e9;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Bricolage Grotesque', sans-serif;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
.app-root {
  position: relative;
  display: flex; flex-direction: column;
  background: linear-gradient(160deg, var(--bg1), var(--bg3));
  transition: background 0.5s ease, color 0.4s ease;
  overflow-x: hidden;
}
.app-root > *:not(.mesh-bg) { position: relative; z-index: 1; }

/* ---- Animated mesh gradient background ---- */
.mesh-bg {
  position: fixed; inset: -25%; z-index: 0; pointer-events: none;
  overflow: hidden;
  filter: blur(90px) saturate(150%);
  transition: filter 0.4s ease;
}
.mesh-blob {
  position: absolute; width: 55vw; height: 55vw; border-radius: 50%;
  opacity: 0.8; mix-blend-mode: screen; will-change: transform;
}
:root[data-theme="light"] .mesh-blob { mix-blend-mode: multiply; opacity: 0.5; }
.mesh-blob.b1 { background: var(--accent1); top: -8%; left: -6%; animation: drift1 19s ease-in-out infinite; }
.mesh-blob.b2 { background: var(--accent2); top: 15%; right: -12%; animation: drift2 23s ease-in-out infinite; }
.mesh-blob.b3 { background: var(--accent3); bottom: -18%; left: 18%; animation: drift3 21s ease-in-out infinite; }
.mesh-blob.b4 { background: var(--bg2); top: 38%; left: 34%; width: 42vw; height: 42vw; animation: drift4 27s ease-in-out infinite; }
.mesh-grain {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.06), transparent 60%);
  animation: pulseGrain 8s ease-in-out infinite;
}
@keyframes drift1 { 0%,100%{transform:translate(0,0) scale(1)} 33%{transform:translate(12vw,9vh) scale(1.18)} 66%{transform:translate(-7vw,15vh) scale(0.88)} }
@keyframes drift2 { 0%,100%{transform:translate(0,0) scale(1)} 33%{transform:translate(-15vw,11vh) scale(0.82)} 66%{transform:translate(-4vw,-9vh) scale(1.22)} }
@keyframes drift3 { 0%,100%{transform:translate(0,0) scale(1)} 33%{transform:translate(11vw,-11vh) scale(1.12)} 66%{transform:translate(19vw,5vh) scale(0.92)} }
@keyframes drift4 { 0%,100%{transform:translate(0,0) scale(1)} 50%{transform:translate(-13vw,-7vh) scale(1.28)} }
@keyframes pulseGrain { 0%,100%{opacity:0.5} 50%{opacity:1} }
.app-dragging .mesh-bg { filter: blur(60px) saturate(200%); }
@media (prefers-reduced-motion: reduce) {
  .mesh-blob, .mesh-grain, .logo-icon, .empty-icon, .icon-sun, .icon-moon, .sparkle-pulse { animation: none !important; }
}

/* ---- Glass surfaces ---- */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--glass-shadow);
  transition: all 0.3s ease;
}
.glass-nav {
  position: relative; z-index: 2;
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}
footer.glass-nav { border-bottom: none; border-top: 1px solid var(--glass-border); }

.logo-text, .hero-title {
  background: linear-gradient(100deg, var(--accent1), var(--accent2) 55%, var(--accent3));
  background-size: 200% 200%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shift 8s ease infinite;
}
.hero-title { line-height: 1.05; }
.tagline { font-family: 'Space Mono', monospace; }

/* ---- Icon system ---- */
.icon-wrap { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.icon-wrap svg { width: 100%; height: 100%; display: block; }
.spin { transform-origin: 50% 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.logo-icon { color: var(--accent1); display: inline-flex; animation: logoFloat 4s ease-in-out infinite; }
@keyframes logoFloat { 0%,100%{transform:translateY(0) rotate(0)} 50%{transform:translateY(-3px) rotate(-4deg)} }
.empty-icon { color: var(--accent2); display: inline-flex; opacity: 0.85; animation: logoFloat 4s ease-in-out infinite; }
.icon-sun { animation: sunPulse 3s ease-in-out infinite; }
.icon-moon { animation: moonBob 3s ease-in-out infinite; }
@keyframes sunPulse { 0%,100%{transform:rotate(0) scale(1)} 50%{transform:rotate(25deg) scale(1.1)} }
@keyframes moonBob { 0%,100%{transform:translateY(0) rotate(0)} 50%{transform:translateY(-2px) rotate(-8deg)} }
.sparkle-pulse { animation: sparklePulse 1.6s ease-in-out infinite; }
@keyframes sparklePulse { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(1.18);opacity:0.8} }
.drop-icon { color: var(--accent2); animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }

/* ---- Entrance reveal ---- */
.reveal { opacity: 0; animation: revealUp 0.6s cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes revealUp { from { opacity:0; transform: translateY(24px); } to { opacity:1; transform:none; } }

.theme-toggle { color: var(--text); }
.theme-toggle:hover { transform: rotate(18deg) scale(1.1); }
.theme-toggle:active { transform: scale(0.9); }
.hover-lift { color: var(--text); }
.hover-lift:hover { transform: translateY(-2px); }

.fav-active { border-color: var(--accent1) !important; color: var(--accent1) !important; box-shadow: 0 0 18px rgba(255,94,156,0.4); }

.gen-panel:focus-within { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(123,94,255,0.25), var(--glass-shadow); }
.gen-input { color: var(--text); min-height: 3rem; }
.gen-input::placeholder { color: var(--text-dim); opacity: 0.7; }

.ratio-chip, .cat-pill {
  padding: 0.45rem 0.9rem; border-radius: 999px; font-size: 0.8rem;
  border: 1px solid var(--glass-border); background: var(--glass-bg);
  color: var(--text-dim); cursor: pointer; transition: all 0.2s ease;
  font-family: 'Space Mono', monospace;
}
.ratio-chip:hover, .cat-pill:hover { color: var(--text); transform: translateY(-2px); }
.chip-active, .cat-active {
  background: linear-gradient(100deg, var(--accent2), var(--accent1));
  color: #fff; border-color: transparent;
  box-shadow: 0 6px 20px rgba(123,94,255,0.4);
}

.grad-btn {
  background: linear-gradient(100deg, var(--accent1), var(--accent2) 60%, var(--accent3));
  background-size: 200% 200%; color: #fff; border: none; cursor: pointer;
  animation: shift 5s ease infinite; box-shadow: 0 8px 28px rgba(123,94,255,0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.grad-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(123,94,255,0.55); }
.grad-btn:active:not(:disabled) { transform: translateY(0); }
@keyframes shift { 0%,100%{background-position:0% 50%} 50%{background-position:100% 50%} }

.gen-loading { animation: revealUp 0.4s ease both; }

.wp-grid {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(1, 1fr);
}
@media (min-width: 640px) { .wp-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .wp-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .wp-grid { grid-template-columns: repeat(4, 1fr); } }

.wp-card { display: flex; flex-direction: column; animation: rise 0.55s cubic-bezier(.2,.7,.3,1) both; transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease; }
.wp-card:hover { transform: translateY(-6px); box-shadow: 0 18px 50px rgba(0,0,0,0.45); }
.wp-card.dying { animation: die 0.32s ease forwards; }
@keyframes rise { from { opacity:0; transform: translateY(22px) scale(0.96); } to { opacity:1; transform:none; } }
@keyframes die { to { opacity:0; transform: scale(0.85) translateY(10px); } }

.img-wrap { position: relative; width: 100%; aspect-ratio: 16/10; overflow: hidden; background: rgba(0,0,0,0.15); }
.wp-card.tall .img-wrap { aspect-ratio: 3/4; }
.wp-img { width: 100%; height: 100%; object-fit: cover; transition: opacity 0.6s ease, transform 0.5s ease; }
.wp-card:hover .wp-img { transform: scale(1.06); }

.upload-badge {
  position: absolute; top: 0.6rem; left: 0.6rem; z-index: 2;
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(120deg, var(--accent2), var(--accent1)); color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  animation: badgePop 0.4s cubic-bezier(.2,.8,.3,1.4) both;
}
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }

.wp-overlay {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  padding: 0.8rem; opacity: 0; transition: opacity 0.3s ease;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent 60%);
}
.wp-card:hover .wp-overlay, .wp-overlay:focus-within { opacity: 1; }
@media (hover: none) { .wp-overlay { opacity: 1; } }
.wp-actions { display: flex; gap: 0.55rem; }
.act-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.18); backdrop-filter: blur(10px); cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #fff;
  transition: transform 0.25s cubic-bezier(.2,.8,.3,1.4), background 0.2s ease, opacity 0.25s ease;
  transform: translateY(10px); opacity: 0;
}
.wp-card:hover .act-btn, .wp-overlay:focus-within .act-btn { transform: translateY(0); opacity: 1; }
@media (hover: none) { .act-btn { transform: none; opacity: 1; } }
.act-btn:hover { transform: scale(1.15) !important; background: rgba(255,255,255,0.32); }
.act-btn:active { transform: scale(0.92) !important; }
.act-btn.faved { background: var(--accent1); border-color: var(--accent1); color: #fff; }
.act-btn.act-danger:hover { background: #ff3b5c; border-color: #ff3b5c; }

.wp-meta { padding: 0.7rem 0.9rem; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.wp-prompt { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-tag { font-size: 0.65rem; font-family: 'Space Mono', monospace; padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--glass-bg); border: 1px solid var(--glass-border); color: var(--text); flex-shrink: 0; }

.empty-state { animation: revealUp 0.5s ease both; }

.shimmer {
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,0.14) 50%, transparent 80%);
  background-size: 200% 100%; animation: sh 1.3s linear infinite;
}
@keyframes sh { 0%{background-position:-100% 0} 100%{background-position:100% 0} }

/* ---- Drag & drop overlay ---- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(10px); animation: fade 0.2s ease;
}
.drop-card {
  padding: 2.5rem 3.2rem; border-radius: 28px; text-align: center;
  border: 2px dashed var(--accent2); color: var(--text);
  animation: pop 0.3s cubic-bezier(.2,.8,.3,1.3);
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: rgba(0,0,0,0.72); backdrop-filter: blur(12px);
  animation: fade 0.25s ease;
}
@keyframes fade { from { opacity:0 } to { opacity:1 } }
.modal-frame { max-width: 92vw; max-height: 92vh; border-radius: 24px; padding: 0.6rem; display: flex; flex-direction: column; animation: pop 0.35s cubic-bezier(.2,.8,.3,1.3); }
@keyframes pop { from { transform: scale(0.9); opacity:0 } to { transform: scale(1); opacity:1 } }
.modal-img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 16px; }
.modal-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.4rem 0.2rem; flex-wrap: wrap; }
.modal-prompt { font-size: 0.85rem; color: var(--text-dim); flex: 1; min-width: 120px; }
.modal-bar button { border: 1px solid var(--glass-border); color: var(--text); cursor: pointer; }
.modal-bar .grad-btn { color: #fff; border: none; }

.remix-link { color: var(--accent1); text-decoration: none; font-weight: 700; font-family: 'Space Mono', monospace; }
.remix-link:hover { text-decoration: underline; }

/* ---- Sparkle burst ---- */
.spark-layer { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.spark { position: absolute; color: var(--accent3); display: inline-flex; animation: burst 1.3s ease forwards; filter: drop-shadow(0 0 8px var(--accent1)); }
@keyframes burst {
  0%{ transform: translate(0,0) scale(0) rotate(0); opacity:1 }
  40%{ opacity:1 }
  100%{ transform: translate(var(--sx,0), var(--sy,-40px)) scale(1.6) rotate(180deg); opacity:0 }
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--accent2); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }