body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.material-symbols-outlined {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.material-symbols-outlined svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

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

:root {
  --primary: #a35dea;
  --primary-hover: #b673f0;
  --primary-dim: rgba(163, 93, 234, 0.7);
  --primary-5: rgba(163, 93, 234, 0.05);
  --primary-10: rgba(163, 93, 234, 0.1);
  --primary-20: rgba(163, 93, 234, 0.2);
  --primary-30: rgba(163, 93, 234, 0.3);
  --bg: #191121;
  --bg-50: rgba(25, 17, 33, 0.5);
  --bg-80: rgba(25, 17, 33, 0.8);
  --surface: #251b2e;
  --surface-30: rgba(37, 27, 46, 0.3);
  --border: #3a2d47;
  --text: #f1ecf5;
  --text-dim: #a89bb5;
  --text-faint: #6f5f80;
  --white: #ffffff;
  --red: #ef4444;
  --green: #22c55e;
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; }

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
}

/* ── Header ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-50);
  backdrop-filter: blur(20px);
  position: sticky; top: 0; z-index: 50;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  background: var(--primary); padding: 7px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px var(--primary-30);
}
.logo-icon .material-symbols-outlined { color: var(--white); font-size: 20px; }
.logo h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.2; }
.logo-sub { font-size: 11px; color: var(--primary-dim); font-weight: 500; margin-top: 1px; }

/* ── App shell ── */
.app { display: flex; flex: 1; min-height: calc(100vh - 61px); }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width, 320px);
  min-width: var(--sidebar-width, 320px);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 61px);
  position: sticky;
  top: 61px;
  z-index: 10;
  transition: width 0.05s linear;
}

/* ── Resizer ── */
.resizer {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  z-index: 20;
  transition: background 0.2s, width 0.2s;
  position: relative;
}
.resizer::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: -2px; right: -2px;
}
.resizer:hover, .resizer.active {
  background: var(--primary-30);
  width: 4px;
}

.sidebar-scroll {
  flex: 1; overflow-y: auto; padding: 20px 20px 24px;
  display: flex; flex-direction: column; gap: 28px;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-80);
}

/* ── Section headers ── */
.s-head { display: flex; align-items: center; gap: 8px; color: var(--primary); margin-bottom: 14px; }
.s-head .material-symbols-outlined { font-size: 18px; }
.s-head h3 { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; }

/* ── Layout picker ── */
.layout-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lay-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: 10px 4px;
  border: 1px solid var(--border); border-radius: 12px;
  background: transparent; cursor: pointer;
  transition: all 0.18s ease; color: var(--text);
  user-select: none;
}
.lay-btn:hover { border-color: rgba(163,93,234,0.5); }
.lay-btn.active {
  border: 2px solid var(--primary);
  background: var(--primary-10);
}
.lay-btn .material-symbols-outlined, .lay-btn .lay-svg { font-size: 26px; opacity: 0.5; transition: opacity 0.2s; }
.lay-btn.active .material-symbols-outlined, .lay-btn.active .lay-svg { color: var(--primary); opacity: 1; }
.lay-name { font-size: 11px; font-weight: 600; color: var(--text-dim); }
.lay-btn.active .lay-name { color: var(--primary); }

/* ── Image slots ── */
.slots-wrap { display: flex; flex-direction: column; gap: 10px; }

/* Images Library Header Button */
.header-add-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
}
.header-add-btn:hover { transform: scale(1.1); opacity: 0.9; }
.header-add-btn:disabled { opacity: 0.35; cursor: default; }

.slots-grid {
  display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px;
}

.slot {
  position: relative; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #1f1826 0%, #150f1d 100%);
  cursor: pointer; transition: all 0.2s;
  width: calc(33.333% - 8px); aspect-ratio: 1/1;
  display: flex; align-items: center; justify-content: center;
}
.slot:hover { border-color: var(--primary-dim); transform: translateY(-2px); }
.slot.empty { border-style: solid; } /* Solid default in screenshot */
.slot .slot-icon { color: var(--text-faint); font-size: 24px; }
.slot:hover .slot-icon { color: var(--primary); }
.slot .slot-label { display: none; } /* Labels are not in the screenshot */

/* Add slot button from previous version — removing as it shifted to header */
.add-slot-btn { display: none; }

/* Filled slot */
.slot.filled { border-style: solid; padding: 0; }
.slot-thumb { width: 100%; height: 100%; object-fit: cover; display: block; position: absolute; inset: 0; }
.slot-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity 0.2s;
}
.slot.filled:hover .slot-overlay { opacity: 1; }
.slot-ol-btn {
  width: 36px; height: 36px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.2); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s; color: var(--white);
}
.slot-ol-btn:hover { background: rgba(255,255,255,0.35); }
.slot-ol-btn.delete:hover { background: rgba(239,68,68,0.7); }
.slot-fname {
  position: absolute; bottom: 6px; left: 8px; right: 8px;
  font-size: 10px; font-weight: 600; color: var(--white);
  background: var(--bg-80); backdrop-filter: blur(6px);
  padding: 4px 8px; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}

input[type=file] { display: none; }

/* ── Sliders ── */
.setting { display: flex; flex-direction: column; gap: 8px; }
.setting-head { display: flex; justify-content: space-between; align-items: center; }
.setting-head label { font-size: 12px; font-weight: 500; }
.setting-head em { font-style: normal; font-weight: 700; color: var(--primary); font-size: 12px; }

input[type=range] {
  appearance: none; -webkit-appearance: none; width: 100%; height: 6px;
  background: var(--border); border-radius: 6px;
  outline: none; cursor: pointer;
  accent-color: var(--primary);
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 2px 8px var(--primary-30);
  cursor: pointer; transition: transform 0.15s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* ── Color pickers ── */
.color-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 4px; }
.cpg-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px; }
.cpg-swatch {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; position: relative;
  transition: border-color 0.2s;
}
.cpg-swatch:hover { border-color: rgba(163,93,234,0.5); }
.cpg-dot { width: 22px; height: 22px; border-radius: 6px; border: 2px solid rgba(255,255,255,0.15); flex-shrink: 0; }
.cpg-hex { font-size: 10px; font-family: 'SF Mono', 'Menlo', monospace; color: var(--text-dim); }
.cpg-swatch input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* ── Download button ── */
.btn-download {
  width: 100%; padding: 13px; border-radius: 12px;
  border: none; cursor: pointer; font-family: inherit; font-weight: 700; font-size: 14px;
  background: var(--primary); color: var(--white);
  box-shadow: 0 6px 20px var(--primary-20);
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-download:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 8px 28px var(--primary-30); }
.btn-download:active { transform: translateY(0) scale(0.98); }
.btn-download:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-download .material-symbols-outlined { font-size: 20px; }

/* ── Canvas area ── */
.canvas-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px; position: relative;
  background: var(--surface-30);
  overflow: hidden;
  transition: background 0.2s;
}
.canvas-area.drag-over {
  background: var(--primary-10);
  outline: 2px dashed var(--primary);
  outline-offset: -20px;
}
.canvas-area.drag-over .empty-state, 
.canvas-area.drag-over #outputCanvas,
.canvas-area.drag-over #previewImg { opacity: 0; pointer-events: none; }
.canvas-area.drag-over .drop-hint { display: flex; }

.drop-hint {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--primary); z-index: 10;
  pointer-events: none; animation: hintFade 0.2s ease;
}
.drop-hint p { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
@keyframes hintFade { from{opacity:0;transform:scale(0.9)} to{opacity:1;transform:scale(1)} }

.empty-state { text-align: center; z-index: 1; opacity: 0.7; pointer-events: none; transition: opacity 0.2s; }
.empty-state .material-symbols-outlined { 
  width: 72px; height: 72px;
  color: var(--primary-30); margin: 0 auto 16px; display: flex; 
}
.empty-state p { color: var(--text-dim); font-size: 14px; line-height: 1.7; }
.empty-state strong { color: var(--text-main); }

#outputCanvas {
  display: none; max-width: 100%; max-height: calc(100vh - 160px);
  border-radius: 16px;
  box-shadow: 0 28px 80px rgba(0,0,0,0.65), 0 0 0 1px rgba(255,255,255,0.04);
  animation: canvasFadeIn 0.35s ease;
}
@keyframes canvasFadeIn { from{opacity:0;transform:scale(.97)} to{opacity:1;transform:scale(1)} }

/* ── Generating badge ── */
.gen-badge {
  position: absolute; top: 16px; right: 16px;
  display: none; align-items: center; gap: 8px;
  background: var(--primary-10); border: 1px solid var(--primary-30);
  color: var(--primary); padding: 6px 14px; border-radius: 30px;
  font-size: 11px; font-weight: 700;
}
.gen-badge.show { display: flex; }
.gen-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary);
  animation: genPulse 0.8s infinite ease-in-out;
}
@keyframes genPulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.3;transform:scale(.5)} }

/* Grid Controls */
#gridSettings {
  display: none;
  background: var(--surface-30);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  flex-direction: column;
  gap: 12px;
}
#gridSettings.show { display: flex; }
.grid-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-input-group label {
  display: block; font-size: 10px; font-weight: 700;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}
.grid-input-group input {
  width: 100%; height: 36px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 0 10px; font-family: inherit; font-weight: 600;
  outline: none; transition: border-color 0.2s;
}
.grid-input-group input:focus { border-color: var(--primary); }

/* Toast */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 30px; font-size: 13px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: none; z-index: 999; white-space: nowrap;
}
#toast.show { display: block; animation: toastUp 0.3s ease; }
#toast.ok { border-color: rgba(34,197,94,0.4); color: var(--green); }
#toast.err { border-color: rgba(239,68,68,0.3); color: var(--red); }
@keyframes toastUp { from{opacity:0;transform:translateX(-50%) translateY(12px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }
