* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0f1115; color: #e6e6e6; }

header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: #161922; border-bottom: 1px solid #232735;
}
header h1 { margin: 0; font-size: 20px; font-weight: 600; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: linear-gradient(90deg, #8b5cf6, #ec4899); color: white; font-weight: 600;
}
.header-actions { margin-left: auto; display: flex; gap: 8px; }
.header-actions button {
  background: #232735; color: #e6e6e6; border: 1px solid #2d3142;
  border-radius: 6px; padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.header-actions button:hover { background: #2d3142; }
.header-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

main { display: flex; height: calc(100vh - 51px); }

.toolbar {
  width: 260px; padding: 16px; background: #161922; border-right: 1px solid #232735;
  display: flex; flex-direction: column; gap: 8px; overflow-y: auto;
}

.toolbar button, .toolbar .btn {
  display: block; width: 100%; padding: 10px 12px; font-size: 14px;
  background: #232735; color: #e6e6e6; border: 1px solid #2d3142;
  border-radius: 6px; cursor: pointer; text-align: center; transition: all 0.15s;
}
.toolbar button:hover, .toolbar .btn:hover { background: #2d3142; border-color: #3a3f55; }
.toolbar button.active { background: #6366f1; border-color: #818cf8; }
.toolbar .primary { background: #10b981; border-color: #34d399; }
.toolbar .primary:hover { background: #059669; }
.toolbar .danger { background: #ef4444; border-color: #f87171; }
.toolbar .danger:hover { background: #dc2626; }
.toolbar .upload { display: block; }

.divider { height: 1px; background: #232735; margin: 6px 0; }
.hint { font-size: 11px; color: #9ca3af; padding: 6px 4px; line-height: 1.4; min-height: 32px; }

.group { display: flex; flex-direction: column; gap: 8px; padding: 8px; background: #1c2030; border-radius: 6px; border: 1px solid #232735; }
.group-title { font-size: 11px; color: #6366f1; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; }
.group.editing-layer { border-color: #6366f1; }
.group.editing-layer .group-title { color: #a78bfa; }
.group label { font-size: 12px; color: #9ca3af; display: flex; flex-direction: column; gap: 4px; }
.group label.check { flex-direction: row; align-items: center; gap: 6px; }
.group input, .group select {
  background: #0f1115; color: #e6e6e6; border: 1px solid #2d3142;
  border-radius: 4px; padding: 6px 8px; font-size: 14px; width: 100%;
}

.layers-panel { font-size: 12px; }
.layers-title { color: #9ca3af; margin-bottom: 6px; }
.layers-list { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.layer-item {
  background: #1c2030; border: 1px solid #2d3142; padding: 6px 8px; border-radius: 4px;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.layer-item.selected { border-color: #6366f1; background: #2d3142; }
.layer-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.layer-item button {
  background: transparent; color: #9ca3af; border: none; cursor: pointer;
  padding: 2px 6px; font-size: 12px; width: auto;
}
.layer-item button:hover { color: #ef4444; }

.canvas-wrap {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  background: #0a0c10; overflow: auto; padding: 20px;
}
.placeholder {
  border: 2px dashed #2d3142; border-radius: 8px; padding: 60px 80px;
  color: #6b7280; text-align: center;
}

.stage {
  position: relative;
  display: inline-block;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.stage canvas { display: block; max-width: 100%; }
#canvas { cursor: crosshair; }
#overlay { position: absolute; inset: 0; pointer-events: none; }

.layer-host { position: absolute; inset: 0; pointer-events: none; }
.text-layer {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  user-select: none;
  white-space: pre;
  transform-origin: top left;
}
.text-layer.selected { outline: 2px dashed #6366f1; outline-offset: 2px; }
.text-layer .layer-handle {
  position: absolute; width: 12px; height: 12px;
  background: #6366f1; border: 2px solid #fff; border-radius: 50%;
  bottom: -8px; right: -8px; cursor: nwse-resize;
}
.text-layer.editing {
  outline: 2px solid #10b981;
  background: rgba(16, 185, 129, 0.08);
}
.text-layer[contenteditable="true"] { cursor: text; }

.status {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); padding: 8px 14px; border-radius: 6px;
  font-size: 13px; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 100;
}
.status.show { opacity: 1; }

.chatbar {
  position: absolute;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px;
  background: rgba(22, 25, 34, 0.96);
  border: 1px solid #2d3142;
  padding: 8px;
  border-radius: 10px;
  width: min(720px, 90%);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.chatbar input {
  flex: 1;
  background: #0f1115; color: #e6e6e6; border: 1px solid #2d3142;
  border-radius: 6px; padding: 9px 12px; font-size: 14px;
}
.chatbar button {
  background: linear-gradient(90deg, #8b5cf6, #ec4899); color: white;
  border: none; padding: 0 18px; border-radius: 6px; cursor: pointer;
  font-weight: 600; font-size: 14px;
}
.chatbar button:hover { filter: brightness(1.1); }
.chatbar button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 768px) {
  main { flex-direction: column; }
  .toolbar { width: 100%; max-height: 40vh; }
}
