/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1a0f;
  --surface: #1a2e1a;
  --surface2: #233a23;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --text: #f0fdf4;
  --muted: #86efac;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.header {
  text-align: center;
  padding: 32px 20px 20px;
  background: linear-gradient(135deg, #0d1f0d 0%, #1a2e1a 100%);
  border-bottom: 1px solid rgba(74,222,128,.15);
}

.logo {
  font-size: 1.8rem;
  font-weight: 800;
  text-decoration: none;
  color: var(--text);
  letter-spacing: 2px;
}
.accent { color: var(--accent); }

.title {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  margin: 8px 0 4px;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  font-size: clamp(.85rem, 2vw, 1rem);
  opacity: .8;
}

.nav-links {
  margin-top: 12px;
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: .85rem;
  opacity: .8;
  transition: opacity .2s;
}
.nav-links a:hover { opacity: 1; }

/* === Main === */
.main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* === Steps === */
.step {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid rgba(74,222,128,.1);
}

.step-title {
  font-size: 1.1rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #0d1f0d;
  border-radius: 50%;
  font-weight: 700;
  font-size: .85rem;
}

/* === Tabs === */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all .2s;
}
.tab-btn.active {
  background: var(--accent);
  color: #0d1f0d;
  font-weight: 600;
}
.tab-btn:hover:not(.active) { background: rgba(74,222,128,.1); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Search === */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-bar input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(74,222,128,.2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: rgba(134,239,172,.4); }

.search-hints {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.chip {
  padding: 4px 12px;
  border: 1px solid rgba(74,222,128,.25);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
}
.chip:hover {
  background: var(--accent);
  color: #0d1f0d;
  border-color: var(--accent);
}

.spinner {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: .9rem;
}
.spinner.hidden { display: none; }

/* === Image Grid === */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
  padding: 4px;
}
.image-grid::-webkit-scrollbar { width: 6px; }
.image-grid::-webkit-scrollbar-track { background: var(--surface2); border-radius: 3px; }
.image-grid::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 3px; }

.grid-item {
  position: relative;
  aspect-ratio: 16/10;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: 2px solid transparent;
}
.grid-item:hover { transform: scale(1.03); box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.grid-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.grid-item .check {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #0d1f0d;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
}
.grid-item.selected .check { display: flex; }
.grid-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  opacity: .6;
}

/* === Upload Zone === */
.upload-zone {
  border: 2px dashed rgba(74,222,128,.3);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(74,222,128,.05);
}
.upload-prompt {
  color: var(--muted);
  opacity: .7;
  font-size: .95rem;
}

/* === Presets === */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.preset-card {
  background: var(--surface2);
  border: 1px solid rgba(74,222,128,.15);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.preset-card:hover {
  border-color: var(--accent);
  background: rgba(74,222,128,.08);
  transform: translateY(-2px);
}
.preset-icon { font-size: 1.8rem; display: block; margin-bottom: 6px; }

/* === Controls === */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.control-group { flex: 1; }
.control-group label {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.control-group input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(74,222,128,.2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-size: .9rem;
  outline: none;
}
.control-group input[type="text"]:focus { border-color: var(--accent); }

.control-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.narrow { min-width: 120px; }

.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.range-val {
  font-size: .8rem;
  color: var(--muted);
  margin-left: 4px;
}

.color-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.color-row input[type="color"] {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--accent) !important; }

.toggle-row {
  display: flex;
  gap: 4px;
}
.toggle-btn {
  padding: 6px 14px;
  border: 1px solid rgba(74,222,128,.2);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-size: .8rem;
  transition: all .2s;
}
.toggle-btn.active {
  background: var(--accent);
  color: #0d1f0d;
  font-weight: 600;
}

.control-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(74,222,128,.2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-size: .85rem;
  outline: none;
  cursor: pointer;
}

/* === Canvas Preview === */
.preview-wrap {
  position: relative;
  background: var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.placeholder-msg {
  position: absolute;
  color: var(--muted);
  opacity: .4;
  font-size: .9rem;
  text-align: center;
  padding: 20px;
  pointer-events: none;
}
.meme-canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* === Action Bar === */
.action-bar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: #0d1f0d;
}
.btn-primary:hover { background: var(--accent-dim); transform: translateY(-1px); }
.btn-outline {
  background: transparent;
  border: 1px solid rgba(74,222,128,.3);
  color: var(--accent);
}
.btn-outline:hover { background: rgba(74,222,128,.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* === Footer === */
.footer {
  text-align: center;
  padding: 24px;
  border-top: 1px solid rgba(74,222,128,.1);
  font-size: .8rem;
  color: var(--muted);
  opacity: .7;
}
.footer a { color: var(--accent); text-decoration: none; }

/* === Responsive === */
@media (max-width: 600px) {
  .main { padding: 16px 10px 40px; }
  .step { padding: 16px; }
  .image-grid { grid-template-columns: repeat(2, 1fr); max-height: 300px; }
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .control-row { flex-direction: column; gap: 10px; }
  .narrow { min-width: unset; }
  .tabs { gap: 2px; padding: 3px; }
  .tab-btn { font-size: .8rem; padding: 8px 10px; }
}