/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0D0D0D;
  --bg2:       #141414;
  --bg3:       #1A1A1A;
  --border:    #2A2A2A;
  --border2:   #333;
  --lime:      #CCFF00;
  --pink:      #FF3CAC;
  --cyan:      #00FFFF;
  --white:     #F0F0F0;
  --muted:     #666;
  --muted2:    #444;
  --font-display: 'Syne', sans-serif;
  --font-mono:    'Space Mono', monospace;
  --radius:    4px;
  --radius-lg: 8px;
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── BACKGROUND EFFECTS ── */
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(204,255,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(204,255,0,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridDrift 20s linear infinite;
}
@keyframes gridDrift {
  0%   { background-position: 0 0; }
  100% { background-position: 40px 40px; }
}

.bg-noise {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

/* ── FLOATING GLYPHS ── */
.float-glyph {
  position: fixed; z-index: 0; pointer-events: none;
  font-family: var(--font-mono); font-size: clamp(60px, 8vw, 120px);
  font-weight: 700; opacity: 0.04; user-select: none;
  animation: floatDrift 15s ease-in-out infinite;
}
.g1 { top: 8%;  left: 3%;  color: var(--lime); animation-duration: 17s; }
.g2 { top: 20%; right: 4%; color: var(--pink); animation-duration: 13s; animation-delay: -4s; }
.g3 { bottom: 30%; left: 6%; color: var(--cyan); animation-duration: 19s; animation-delay: -8s; }
.g4 { bottom: 10%; right: 8%; color: var(--lime); animation-duration: 15s; animation-delay: -2s; }
.g5 { top: 50%; left: 50%; color: var(--pink); animation-duration: 21s; animation-delay: -10s; }

@keyframes floatDrift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  33%       { transform: translateY(-20px) rotate(5deg); }
  66%       { transform: translateY(10px) rotate(-3deg); }
}

/* ── APP WRAPPER ── */
.app-wrapper {
  position: relative; z-index: 1;
  max-width: 900px; margin: 0 auto;
  padding: 0 20px 60px;
}

/* ── HEADER ── */
.site-header {
  text-align: center;
  padding: 60px 20px 40px;
  position: relative;
}

.header-badge {
  display: inline-block;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.25em;
  color: var(--lime); border: 1px solid var(--lime);
  padding: 4px 14px; border-radius: 100px;
  margin-bottom: 20px;
  animation: badgePulse 3s ease-in-out infinite;
}
@keyframes badgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(204,255,0,0); }
  50%       { box-shadow: 0 0 12px 2px rgba(204,255,0,0.2); }
}

.site-title {
  font-family: var(--font-display);
  font-size: clamp(52px, 12vw, 110px);
  font-weight: 800; line-height: 0.9;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}
.title-meme {
  color: var(--lime);
  text-shadow: 0 0 40px rgba(204,255,0,0.4), 0 0 80px rgba(204,255,0,0.15);
  display: inline-block;
  animation: glitchMeme 8s ease-in-out infinite;
}
.title-craft {
  color: var(--pink);
  text-shadow: 0 0 40px rgba(255,60,172,0.4), 0 0 80px rgba(255,60,172,0.15);
  display: inline-block;
}

@keyframes glitchMeme {
  0%, 90%, 100% { transform: none; clip-path: none; }
  92% { transform: translate(-2px, 0) skewX(-2deg); clip-path: polygon(0 20%, 100% 20%, 100% 40%, 0 40%); color: var(--cyan); }
  94% { transform: translate(2px, 0) skewX(2deg); clip-path: polygon(0 60%, 100% 60%, 100% 80%, 0 80%); }
  96% { transform: none; clip-path: none; color: var(--lime); }
}

.site-tagline {
  font-family: var(--font-mono); font-size: clamp(13px, 2vw, 16px);
  color: var(--muted); letter-spacing: 0.05em;
}
.site-tagline em { color: var(--white); font-style: normal; }

/* ── CONTROLS BAR ── */
.controls-bar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px; align-items: end;
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group--actions { display: flex; flex-direction: column; gap: 8px; }

.control-label {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.2em; color: var(--muted);
  text-transform: uppercase;
}

.text-input {
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--white); font-family: var(--font-mono); font-size: 13px;
  padding: 10px 14px; border-radius: var(--radius);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.text-input::placeholder { color: var(--muted2); }
.text-input:focus {
  border-color: var(--lime);
  box-shadow: 0 0 0 2px rgba(204,255,0,0.12);
}

/* ── BUTTONS ── */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  padding: 12px 20px; border-radius: var(--radius);
  border: none; cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  background: var(--lime); color: #0D0D0D;
  box-shadow: 0 0 20px rgba(204,255,0,0.25);
}
.btn--primary:hover {
  background: #d9ff1a;
  box-shadow: 0 0 30px rgba(204,255,0,0.45), 0 4px 20px rgba(204,255,0,0.2);
  transform: translateY(-1px);
}

.btn--secondary {
  background: transparent; color: var(--pink);
  border: 1px solid var(--pink);
  box-shadow: 0 0 12px rgba(255,60,172,0.1);
}
.btn--secondary:hover {
  background: rgba(255,60,172,0.08);
  box-shadow: 0 0 20px rgba(255,60,172,0.25);
  transform: translateY(-1px);
}

.btn--outline {
  background: transparent; color: var(--white);
  border: 1px solid var(--border2);
}
.btn--outline:hover {
  border-color: var(--white);
  background: rgba(255,255,255,0.05);
}

.btn--ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  font-size: 11px; padding: 8px 16px;
}
.btn--ghost:hover { color: var(--white); border-color: var(--white); }

.btn-shimmer {
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.3) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}
.btn--primary:hover .btn-shimmer { transform: translateX(100%); }

.btn-icon { font-size: 14px; }

/* ── MEME STAGE ── */
.meme-stage { margin-bottom: 16px; }

.stage-frame {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 420px;
  display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition);
}
.stage-frame:has(.meme-canvas:not(.hidden)) {
  border-color: var(--border2);
}

/* Loader */
.stage-loader {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 60px;
}
.loader-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--border2);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-text {
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.2em; color: var(--muted);
}
.loader-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* Error */
.stage-error {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 60px; text-align: center;
}
.error-icon { font-size: 32px; color: #FF4500; }
.error-text { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

/* Canvas */
.meme-canvas {
  display: block; max-width: 100%; height: auto;
  border-radius: var(--radius);
  animation: canvasReveal 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes canvasReveal {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* Placeholder */
.stage-placeholder {
  display: flex; align-items: center; justify-content: center;
  padding: 80px 40px;
}
.placeholder-inner { text-align: center; }
.placeholder-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.placeholder-text {
  font-family: var(--font-display); font-size: 18px; font-weight: 700;
  color: var(--muted); margin-bottom: 8px;
}
.placeholder-sub { font-family: var(--font-mono); font-size: 12px; color: var(--muted2); }
.placeholder-sub strong { color: var(--lime); }

/* Meme meta */
.meme-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  letter-spacing: 0.05em;
}
.meta-template { color: var(--white); }
.meta-divider { color: var(--muted2); }

/* ── POST ACTIONS ── */
.post-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.post-actions .btn { flex: 1; min-width: 120px; }

/* ── STYLE CONTROLS ── */
.style-controls {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  margin-bottom: 40px;
}

.style-heading {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.25em; color: var(--muted);
  margin-bottom: 16px;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
}

.style-item { display: flex; flex-direction: column; gap: 8px; }

.range-wrap { display: flex; align-items: center; gap: 10px; }
.range-input {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--border2); border-radius: 2px; outline: none;
  cursor: pointer;
}
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--lime); cursor: pointer;
  box-shadow: 0 0 8px rgba(204,255,0,0.4);
  transition: transform var(--transition);
}
.range-input::-webkit-slider-thumb:hover { transform: scale(1.2); }
.range-val { font-family: var(--font-mono); font-size: 11px; color: var(--lime); min-width: 36px; }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--white); transform: scale(1.1); }

.toggle-group { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle-btn {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em;
  padding: 6px 12px; border-radius: var(--radius);
  background: var(--bg3); color: var(--muted);
  border: 1px solid var(--border2); cursor: pointer;
  transition: all var(--transition);
}
.toggle-btn:hover { color: var(--white); border-color: var(--white); }
.toggle-btn.active {
  background: var(--lime); color: #0D0D0D;
  border-color: var(--lime); font-weight: 700;
}

/* ── GALLERY ── */
.gallery-section { margin-bottom: 60px; }

.gallery-heading {
  display: flex; align-items: center; gap: 16px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.25em; color: var(--muted);
  margin-bottom: 20px;
}
.heading-line {
  flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border2), transparent);
}

.gallery-strip {
  display: flex; gap: 12px; overflow-x: auto;
  padding-bottom: 12px; scroll-snap-type: x mandatory;
}
.gallery-strip::-webkit-scrollbar { height: 4px; }
.gallery-strip::-webkit-scrollbar-track { background: var(--bg2); border-radius: 2px; }
.gallery-strip::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.gallery-strip::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.gallery-empty {
  font-family: var(--font-mono); font-size: 12px; color: var(--muted2);
  padding: 20px 0; width: 100%; text-align: center;
}

.gallery-item {
  flex: 0 0 140px; scroll-snap-align: start;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer; position: relative;
  transition: transform var(--transition), border-color var(--transition);
  animation: galleryIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes galleryIn {
  from { opacity: 0; transform: scale(0.8) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.gallery-item:hover { transform: scale(1.04); border-color: var(--lime); }
.gallery-item img { width: 100%; height: 100px; object-fit: cover; display: block; }
.gallery-item-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 16px 6px 6px;
  font-family: var(--font-mono); font-size: 9px; color: var(--white);
  letter-spacing: 0.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── FOOTER ── */
.site-footer {
  text-align: center; padding: 20px 0;
  border-top: 1px solid var(--border);
}
.footer-text { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.footer-link { color: var(--lime); text-decoration: none; }
.footer-link:hover { text-decoration: underline; }
.footer-count { color: var(--pink); font-weight: 700; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--white); font-family: var(--font-mono); font-size: 12px;
  padding: 10px 20px; border-radius: 100px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1000; pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease;
  opacity: 0; white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── UTILITY ── */
.hidden { display: none !important; }

/* ── RESPONSIVE ── */
@media (max-width: 680px) {
  .controls-bar {
    grid-template-columns: 1fr;
  }
  .control-group--actions {
    flex-direction: row;
  }
  .control-group--actions .btn { flex: 1; }
  .post-actions { flex-direction: column; }
  .post-actions .btn { flex: none; }
  .site-header { padding: 40px 10px 30px; }
}

@media (max-width: 400px) {
  .control-group--actions { flex-direction: column; }
}
