:root {
  --ink: #1a1626;
  --bg1: #f6e7ff;
  --bg2: #ffe3d1;
  --bg3: #d9f7ec;
  --accent: #ff3d7f;
  --accent2: #7b5cff;
  --rail: #ffffff;
  --line: #ece3f5;
  --shadow: 0 10px 30px rgba(90,50,120,.14);
}

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

html, body { height: 100%; }

body {
  font-family: 'Bricolage Grotesque', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 15%, var(--bg1), transparent 45%),
    radial-gradient(circle at 88% 20%, var(--bg2), transparent 42%),
    radial-gradient(circle at 50% 92%, var(--bg3), transparent 48%),
    #fbf7ff;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; animation: wobble 5s ease-in-out infinite; }
@keyframes wobble { 0%,100%{transform:rotate(-6deg)} 50%{transform:rotate(8deg)} }
.brand-text h1 {
  font-size: 22px; font-weight: 800; letter-spacing: -.5px; line-height: 1;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag { font-family: 'Space Mono', monospace; font-size: 10px; letter-spacing: 1px; opacity: .55; text-transform: uppercase; margin-top: 3px; }

.top-actions { display: flex; gap: 10px; align-items: center; }
.ghost-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 14px;
  width: 42px; height: 42px; font-size: 18px; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.ghost-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.ai-btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 800; font-size: 15px;
  color: #fff; padding: 11px 20px; border-radius: 16px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 18px rgba(123,92,255,.35);
  transition: transform .15s, box-shadow .15s;
}
.ai-btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 10px 26px rgba(123,92,255,.45); }
.ai-btn:active { transform: scale(.97); }

/* ---- Stage ---- */
#stage {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 16px;
  min-height: 0;
}

/* ---- Tool rail ---- */
#tool-rail {
  background: var(--rail);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.tool {
  width: 46px; height: 46px; border-radius: 14px; border: 2px solid transparent;
  background: #f7f2ff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s, background .15s, border-color .15s;
}
.tool:hover { transform: scale(1.08); }
.tool.active { border-color: var(--accent); background: #fff0f6; box-shadow: 0 0 0 3px rgba(255,61,127,.15); }
.rail-sep { width: 60%; height: 1px; background: var(--line); margin: 4px 0; }

.color-wrap { width: 46px; height: 46px; border-radius: 14px; overflow: hidden; border: 2px solid var(--line); cursor: pointer; }
#color { width: 150%; height: 150%; border: none; cursor: pointer; transform: translate(-16%,-16%); background: none; padding: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 5px; width: 46px; justify-content: center; }
.swatch { width: 18px; height: 18px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); cursor: pointer; transition: transform .1s; }
.swatch:hover { transform: scale(1.2); }

.size-dots { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.sd { width: 40px; height: 30px; border-radius: 10px; border: 2px solid transparent; background: #f7f2ff; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: border-color .15s; }
.sd span { background: var(--ink); border-radius: 50%; display: block; }
.sd.active { border-color: var(--accent2); background: #f0edff; }

/* ---- Canvas ---- */
#canvas-hold {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  background:
    radial-gradient(circle, rgba(123,92,255,.12) 1px, transparent 1px) 0 0 / 22px 22px,
    #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .2s;
}
#canvas-hold.drag { box-shadow: 0 0 0 4px var(--accent2) inset; }
#canvas {
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(60,30,90,.12);
  touch-action: none;
  cursor: crosshair;
}
#empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; transition: opacity .4s;
}
#empty-hint.gone { opacity: 0; }
.hint-inner { text-align: center; color: #a99cc0; }
.hint-emoji { font-size: 54px; display: block; margin-bottom: 10px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }
.hint-inner p { font-size: 15px; line-height: 1.6; }
.hint-inner kbd { font-family: 'Space Mono', monospace; background: #efe8fa; border-radius: 5px; padding: 1px 6px; font-size: 12px; border: 1px solid #ddd0f0; }

/* ---- Footer ---- */
#footer {
  text-align: center; padding: 8px; font-family: 'Space Mono', monospace;
  font-size: 11px; color: #9a8fb0;
}
#footer a { color: var(--accent2); font-weight: 700; text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* ---- AI overlay ---- */
#ai-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30,20,50,.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadein .2s ease;
}
@keyframes fadein { from{opacity:0} to{opacity:1} }
#ai-overlay.hidden { display: none; }
#ai-panel {
  width: 100%; max-width: 460px;
  background: #fff; border-radius: 26px; padding: 22px;
  box-shadow: 0 30px 60px rgba(40,20,70,.35);
  animation: pop .25s cubic-bezier(.3,1.4,.5,1);
}
@keyframes pop { from{transform:scale(.9);opacity:0} to{transform:scale(1);opacity:1} }
.ai-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.ai-head h2 { font-size: 22px; font-weight: 800; }
.ai-tabs { display: flex; gap: 8px; background: #f4eefc; padding: 5px; border-radius: 14px; margin-bottom: 16px; }
.ai-tab {
  flex: 1; border: none; background: transparent; padding: 9px; border-radius: 10px;
  font-family: inherit; font-weight: 700; font-size: 14px; color: #8a7ba5; cursor: pointer;
  transition: all .18s;
}
.ai-tab.active { background: #fff; color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

#ai-prompt {
  width: 100%; min-height: 90px; resize: vertical;
  border: 2px solid var(--line); border-radius: 16px; padding: 14px;
  font-family: inherit; font-size: 15px; color: var(--ink);
  transition: border-color .15s;
}
#ai-prompt:focus { outline: none; border-color: var(--accent2); }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.preset {
  border: 1px solid var(--line); background: #f9f5ff; border-radius: 999px;
  padding: 7px 13px; font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.preset:hover { background: var(--accent2); color: #fff; border-color: var(--accent2); transform: translateY(-1px); }

.ai-go-btn {
  width: 100%; border: none; cursor: pointer; font-family: inherit; font-weight: 800; font-size: 17px;
  color: #fff; padding: 15px; border-radius: 18px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  box-shadow: 0 8px 22px rgba(123,92,255,.4);
  transition: transform .15s;
}
.ai-go-btn:hover:not(:disabled) { transform: translateY(-2px); }
.ai-go-btn:disabled { opacity: .6; cursor: wait; }

#ai-status { margin-top: 14px; text-align: center; font-size: 14px; min-height: 20px; font-weight: 600; }
#ai-status.ok { color: #1cc98d; }
#ai-status.err { color: var(--accent); }
.spinner {
  display: inline-block; width: 16px; height: 16px; vertical-align: middle;
  border: 3px solid #eee; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Confetti ---- */
.confetti {
  position: fixed; font-size: 22px; z-index: 300; pointer-events: none;
  animation: burst 1.1s ease-out forwards;
}
@keyframes burst {
  0% { transform: translate(0,0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ---- Mobile ---- */
@media (max-width: 720px) {
  #stage { flex-direction: column-reverse; padding: 10px; gap: 10px; }
  #tool-rail {
    flex-direction: row; width: 100%; overflow-x: auto; overflow-y: hidden;
    padding: 8px 10px; border-radius: 18px;
  }
  .rail-sep { width: 1px; height: 60%; margin: 0 4px; }
  .swatches { width: auto; flex-wrap: nowrap; }
  .size-dots { flex-direction: row; }
  .brand-text h1 { font-size: 18px; }
  .tag { display: none; }
  .ai-btn { padding: 10px 14px; font-size: 14px; }
  #ai-panel { border-radius: 22px; }
}
</parameter>