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

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c27;
  --surface3: #252535;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --accent: #7c6aff;
  --accent2: #ff6ab0;
  --accent3: #6affda;
  --text: #f0f0f8;
  --text2: #8888aa;
  --text3: #555570;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body { height: 100%; }

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,15,0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 18px; font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
header h1 {
  font-family: 'Syne', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
header span { color: var(--text2); font-size: 0.8rem; font-weight: 400; margin-left: 4px; }
.header-badge {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent3);
  background: rgba(106,255,218,0.1);
  border: 1px solid rgba(106,255,218,0.2);
  padding: 4px 10px;
  border-radius: 20px;
}

/* ── Layout ── */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

.sidebar-section {
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  position: relative;
}
.section-header:hover { background: var(--surface2); }
.section-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px;
  flex-shrink: 0;
}
.section-header h3 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text2);
  flex: 1;
}
.section-chevron {
  font-size: 10px;
  color: var(--text3);
  transition: transform 0.2s;
}
.section-header.open .section-chevron { transform: rotate(180deg); }
.section-body {
  padding: 0 20px 16px;
  display: none;
}
.section-body.open { display: block; }

/* ── Controls ── */
.control { margin-bottom: 14px; }
.control:last-child { margin-bottom: 0; }
label.ctrl-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,106,255,0.15);
}
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666688' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer; }
option { background: #1c1c27; }

input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  background: var(--surface3);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,106,255,0.2);
  cursor: grab;
}
.range-row { display: flex; align-items: center; gap: 10px; }
.range-val {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="color"] {
  width: 100%; height: 36px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px 4px;
}

.color-row { display: flex; gap: 8px; align-items: center; }
.color-swatch { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; }

/* Segmented control */
.seg-ctrl {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.seg-ctrl button {
  flex: 1;
  padding: 5px 4px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.02em;
}
.seg-ctrl button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(124,106,255,0.35);
}

/* Upload zones */
.upload-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.upload-zone:hover { border-color: var(--accent); background: rgba(124,106,255,0.06); }
.upload-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-zone .upload-icon { font-size: 24px; margin-bottom: 6px; }
.upload-zone p { font-size: 0.75rem; color: var(--text2); line-height: 1.4; }
.upload-zone p strong { color: var(--text); display: block; margin-bottom: 2px; font-size: 0.78rem; }
.upload-zone.has-file { border-color: var(--accent3); background: rgba(106,255,218,0.05); }
.upload-zone.has-file .upload-icon::after { content: ' ✓'; color: var(--accent3); }

/* Position grid */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.pos-grid button {
  aspect-ratio: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text3);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  display: grid; place-items: center;
}
.pos-grid button:hover { border-color: var(--accent); color: var(--text); }
.pos-grid button.active { background: rgba(124,106,255,0.2); border-color: var(--accent); color: var(--accent); }

/* Gradient controls */
.grad-row { display: flex; gap: 8px; align-items: flex-end; }
.grad-row .control { flex: 1; margin-bottom: 0; }
.grad-stop-row { display: flex; gap: 8px; }
.grad-stop { flex: 1; }

/* ── Main canvas area ── */
.canvas-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 32px;
  gap: 24px;
  overflow: auto;
  background: radial-gradient(ellipse at 60% 20%, rgba(124,106,255,0.06) 0%, transparent 60%),
              radial-gradient(ellipse at 20% 80%, rgba(255,106,176,0.04) 0%, transparent 50%);
}

.canvas-frame {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--border2), 0 24px 80px rgba(0,0,0,0.6), 0 0 0 8px rgba(255,255,255,0.02);
  flex-shrink: 0;
  transition: box-shadow 0.3s;
}
.canvas-frame:hover { box-shadow: 0 0 0 1px var(--border2), 0 24px 80px rgba(0,0,0,0.7), 0 0 0 8px rgba(255,255,255,0.03), 0 0 40px rgba(124,106,255,0.1); }

#og-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.size-label {
  font-size: 0.72rem;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  letter-spacing: 0.02em;
}
.btn-ghost {
  background: var(--surface);
  color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9b6aff);
  color: #fff;
  box-shadow: 0 4px 16px rgba(124,106,255,0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(124,106,255,0.45); }
.btn-primary:active { transform: none; }

.download-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.fmt-btn {
  padding: 8px 12px;
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text2);
  transition: all 0.15s;
}
.fmt-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Pill */
.pill {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  vertical-align: middle;
}
.pill-purple { background: rgba(124,106,255,0.15); color: var(--accent); }

/* ── Scrollbar for canvas area ── */
.canvas-area::-webkit-scrollbar { width: 6px; height: 6px; }
.canvas-area::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  z-index: 9999;
  backdrop-filter: blur(10px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { max-height: 50vh; }
  .canvas-area { padding: 20px 16px; }
}
