:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;

  --success: #10b981;
  --success-600: #059669;
  --danger: #ef4444;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --shadow-xs: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 6px 16px -4px rgba(15,23,42,0.10), 0 2px 4px -2px rgba(15,23,42,0.06);
  --shadow-lg: 0 20px 40px -12px rgba(15,23,42,0.18);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(79,70,229,0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(16,185,129,0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: white;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  box-shadow: var(--shadow-sm);
}
.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}
.appbar-actions { display: flex; align-items: center; gap: var(--space-2); }

/* ---------- Tip Jar ---------- */
.tip-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: var(--space-3);
}
.tip-arrow {
  position: absolute;
  right: calc(100% + 6px);
  top: 50%;
  transform: translateY(-55%);
  display: flex;
  align-items: center;
  gap: 4px;
  color: #b45309;
  pointer-events: none;
  white-space: nowrap;
  animation: tipBob 2.4s ease-in-out infinite;
}
.tip-arrow svg { display: block; }
.tip-arrow-label {
  font-family: 'Caveat', 'Inter', cursive;
  font-size: 0.95rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.01em;
  color: #b45309;
  transform: translateY(-2px);
}
.tip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.875rem;
  color: #78350f;
  background: linear-gradient(135deg, #fde68a, #fbbf24);
  border: 1px solid #f59e0b;
  box-shadow: 0 2px 6px rgba(245,158,11,0.35), inset 0 1px 0 rgba(255,255,255,0.6);
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.tip-btn:hover {
  transform: translateY(-1px) scale(1.03);
  filter: brightness(1.05);
  box-shadow: 0 6px 14px rgba(245,158,11,0.45), inset 0 1px 0 rgba(255,255,255,0.7);
  text-decoration: none;
}
.tip-emoji {
  font-size: 1.05rem;
  display: inline-block;
  animation: tipWiggle 2.4s ease-in-out infinite;
  transform-origin: 50% 70%;
}
@keyframes tipBob {
  0%, 100% { transform: translateY(-55%) translateX(0); }
  50%      { transform: translateY(-55%) translateX(-4px); }
}
@keyframes tipWiggle {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(-12deg); }
  40%      { transform: rotate(10deg); }
  60%      { transform: rotate(-6deg); }
  80%      { transform: rotate(4deg); }
}
@media (max-width: 720px) {
  .tip-arrow { display: none; }
}

.ghost-btn, .primary-btn {
  display: inline-flex; align-items: center;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  transition: all .15s ease;
}
.ghost-btn { color: var(--text); border: 1px solid var(--border); background: var(--surface); }
.ghost-btn:hover { background: var(--surface-2); text-decoration: none; }
.primary-btn { color: #fff; background: var(--primary); border: 1px solid var(--primary); }
.primary-btn:hover { background: var(--primary-600); border-color: var(--primary-600); text-decoration: none; }

/* ---------- Workspace layout ---------- */
.workspace {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-6);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-6);
  align-items: start;
}
.main-col { display: flex; flex-direction: column; gap: var(--space-6); min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: var(--space-4); position: sticky; top: 80px; }

@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.step-card { padding: var(--space-6); }

.step-header {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  margin-bottom: var(--space-5);
}
.step-num {
  flex-shrink: 0;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--primary-100);
  color: var(--primary-600);
  font-weight: 700;
  font-size: 0.9rem;
}
.step-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.step-header p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Upload area ---------- */
.upload-area {
  border: 2px dashed var(--border-strong);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all .2s ease;
  color: var(--text-muted);
}
.upload-area:hover, .upload-area.hover {
  border-color: var(--primary);
  background: var(--primary-50);
  color: var(--primary-600);
}
.upload-icon {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-3);
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.upload-area:hover .upload-icon { color: var(--primary-600); border-color: var(--primary-100); }
.upload-title { font-weight: 600; color: var(--text); font-size: 1rem; }
.upload-sub { font-size: 0.875rem; margin-top: 4px; }
.upload-link { color: var(--primary); font-weight: 600; }

/* ---------- Uploads list ---------- */
.uploads-container { margin-top: var(--space-5); }
.uploads-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.uploads-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.hint { font-size: 0.8rem; color: var(--text-soft); }

.upload-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
}
.upload-list:empty::after {
  content: 'No designs yet — drop PNGs above to get started.';
  display: block;
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-5);
  color: var(--text-soft);
  font-size: 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.upload-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.85rem;
  transition: all .15s ease;
  box-shadow: var(--shadow-xs);
}
.upload-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.upload-item img {
  width: 100%;
  height: 80px;
  object-fit: contain;
  margin-bottom: var(--space-2);
  cursor: pointer;
  border-radius: 6px;
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
}
.upload-item input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  margin-top: 6px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.delete-button {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(255,255,255,0.95);
  color: var(--danger);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px; height: 24px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: all .15s ease;
  box-shadow: var(--shadow-xs);
}
.delete-button:hover { background: var(--danger); color: white; border-color: var(--danger); }
.view-icon { margin-top: 4px; }
.view-icon span {
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 500;
}
.view-icon span:hover { text-decoration: underline; }
.trim-button {
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
}
.trim-button:hover { background: var(--primary); color: white; border-color: var(--primary); }

/* ---------- Sidebar / settings ---------- */
.sidebar-card { padding: var(--space-6); }

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.field-hint { font-size: 0.75rem; color: var(--text-soft); }

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}
.input-with-suffix { position: relative; }
.input-with-suffix .suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--text-soft);
  pointer-events: none;
}
.input-with-suffix input { padding-right: 56px; }

.actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-600); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, var(--shadow-sm);
}
.btn-success:hover:not(:disabled) { background: var(--success-600); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }

.tips {
  margin-top: var(--space-5);
  padding: var(--space-4);
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  border-radius: var(--radius);
}
.tip-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary-600);
  margin-bottom: 6px;
}
.tips ul { padding-left: 18px; }
.tips li { font-size: 0.85rem; color: var(--text); margin: 4px 0; }

.footer-credits {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: var(--space-3);
}

/* ---------- Preview area ---------- */
.preview-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
@media (max-width: 768px) {
  .preview-grid { grid-template-columns: 1fr; }
}

.stats-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  font-size: 0.875rem;
  min-height: 200px;
}
.stats-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-align: center;
  color: var(--text-soft);
  padding: var(--space-5) var(--space-2);
  height: 100%;
}
.stats-empty-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-soft);
}
.stats-panel.has-render .stats-empty { display: none; }

.stats-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.stats-row:last-of-type { border-bottom: none; }
.stats-row span { color: var(--text-muted); }
.stats-row strong { color: var(--text); font-weight: 600; }
.stats-foot {
  margin-top: var(--space-3);
  font-size: 0.75rem;
  color: var(--text-soft);
}

.canvas-container {
  position: relative;
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-color: #fafbfd;
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  min-height: 320px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.canvas-container canvas { display: none; }
.canvas-container.has-render canvas {
  display: block;
  background: #fff;
  box-shadow: var(--shadow-md);
  border-radius: 4px;
}
.canvas-container.has-render .canvas-empty { display: none; }
.canvas-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--text-soft);
  text-align: center;
  padding: var(--space-6);
}
.canvas-empty-icon {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-soft);
  box-shadow: var(--shadow-xs);
}

/* ---------- Modal ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  padding: var(--space-4);
}
.modal-content {
  background: var(--surface);
  margin: 4vh auto 0;
  width: 100%;
  max-width: 800px;
  border-radius: var(--radius-lg);
  position: relative;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-close {
  position: absolute;
  top: 8px; right: 14px;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-soft);
  cursor: pointer;
  z-index: 2;
}
.modal-close:hover { color: var(--text); }
.modal-controls {
  background: var(--surface-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
}
.modal-controls label { font-weight: 600; color: var(--text); }
.modal-controls input[type="color"] {
  width: 36px; height: 28px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  padding: 0;
}
#modalImage { display: block; max-width: 100%; margin: 0 auto; }

/* ---------- Progress indicator (created in JS) ---------- */
#progressIndicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 100;
}
