:root {
	--primary-color: #007aff;
	--primary-hover-color: #006adb;
	--primary-color-bg: #ecf5ff;
	--light-gray-bg: #f8f8f8;
	--medium-gray-bg: #e5e5e5;
	--radius-small: 6px;
	--light-gray-hover: #f0f0f0;
}

* {
	box-sizing: border-box;
}
::-webkit-scrollbar {
	width: 13px; /* 滚动条的总宽度 */
}

/* 滚动条轨道 */
::-webkit-scrollbar-track {
	background: transparent;
}

/* 滚动条滑块（那个可以拖动的条） */
::-webkit-scrollbar-thumb {
	background-color: #cccccc;
	border-radius: 10px;
	/* 核心技巧：使用透明边框配合 background-clip */
	border: 3px solid transparent;
	background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
	background-color: #ababab;
}

body {
	overflow: hidden;
	margin: 0;
	color: #333;
	font-family:
		-apple-system, "Helvetica Neue", "PingFang SC", "Microsoft YaHei",
		sans-serif;
}

.mt16 {
	margin-top: 16px;
}
.mb8 {
	margin-bottom: 8px;
}

/* 1. 导航栏基础样式 */
.navbar {
	height: 56px;
	background: #ffffff;
	border-bottom: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	z-index: 1000;
	position: relative;
}

input[type="range"] {
	margin: 0;
	padding: 0;
	height: 36px;
}

input[type="range"] {
	-webkit-appearance: none; /* 针对 Chrome/Safari/Edge */
	appearance: none;
	background: transparent; /* 移除背景 */
}
input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	height: 24px;
	width: 24px;
	background-color: white;
	border-radius: 50%; /* 变成圆形 */
	border: 3px solid var(--primary-color);
	margin-top: -9px; /* 关键：让滑块在轨道上居中 */
}
input[type="range"]::-webkit-slider-runnable-track {
	width: 100%;
	height: 6px;
	background: var(--light-gray-hover);
	border-radius: 3px;
}

select {
	padding: 10px 15px;
	font-size: 14px;
	border-radius: var(--radius-small);
	background-color: var(--light-gray-bg);
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	cursor: pointer;
	border: none;
}

select:hover {
	background-color: var(--primary-color-bg);
}

.nav-left {
	flex: 1;
	display: flex;
	align-items: center;
	gap: 24px;
}
.nav-center {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	font-size: 15px;
	font-weight: 600;
	color: #333;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 30%; /* 防止标题过长挤占两边按钮 */
	pointer-events: none; /* 避免挡住底下的点击事件 */
}
/* 3. 右侧导航项 */
.nav-right {
	display: flex;
	align-items: center;
	gap: 20px;
	justify-content: end;
}

.app {
	display: flex;
	/* 减去导航栏的 56px 高度 */
	height: calc(100vh - 56px);
}

.divider {
	height: 1px;
	background-color: #e5e5e5;
}

#leftSidebar {
	width: 320px;
	transition: width 0.3s ease;
	background: white;
	padding: 16px;
}
#layerSection {
	padding: 16px;
	overflow: auto;
}

/* 头部样式：让标题和按钮并排 */
.sidebar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	overflow: hidden; /* 防止文字溢出 */
	white-space: nowrap;
}
.icon-nav {
	width: 18px;
	height: 18px;
}
.template-container {
	height: 50%;
	overflow: auto;
	padding: 16px;
}
/* 确保模板列表在展开时滚动 */
.sidebar-content {
	flex: 1;
}
.section-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 10px;
}
.section-title {
	font-weight: 500;
	color: black;
}
.sidebar button {
	width: 100%;
	margin-bottom: 6px;
}
#templateList {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
	gap: 16px;
}
/* ===== Sidebar Tabs ===== */
.sidebar-tabs {
	display: flex;
	background-color: var(--light-gray-bg);
	border-radius: var(--radius-small);
	padding: 4px;
}

.sidebar-tab {
	flex: 1;
	text-align: center;
	padding: 2px 0;
	font-size: 14px;
	cursor: pointer;
	color: #666;
	user-select: none;
	border-radius: var(--radius-small);
}

.sidebar-tab:hover {
	color: var(--primary-color);
}

.sidebar-tab.active {
	color: var(--primary-color);
	background-color: #fff;
}

.sidebar-panels-container {
	flex: 1;
	overflow: hidden; /* 保证内部可以独立滚动 */
	position: relative;
	display: flex;
	flex-direction: column;
}

.sidebar-panel {
	flex: 1;
	overflow-y: auto;
	height: 100%;
}

/* ===== Asset List Items ===== */
.asset-item {
	border-radius: var(--radius-small);
	overflow: hidden;
	background: var(--light-gray-bg);
	cursor: grab;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1; /* 保持正方形 */
	transition: all 0.2s;
	border: 1px solid transparent;
	position: relative;
}

.asset-item:active {
	cursor: grabbing;
}

.asset-item:hover {
	border-color: var(--primary-color);
	background: var(--primary-color-bg);
}

.asset-item img {
	/* 去掉 max- 前缀，强制撑满并等比缩放 */
	width: 85%;
	height: 85%;
	object-fit: contain;
	pointer-events: none;
}

/* ===== 素材分类 Tabs ===== */
.asset-category-tabs {
	display: flex;
	gap: 8px;
	margin-bottom: 16px;
	overflow-x: auto;
	padding-bottom: 4px; /* 留出呼吸空间 */
	scrollbar-width: none; /* 隐藏 Firefox 滚动条 */
}

.asset-category-tabs::-webkit-scrollbar {
	display: none; /* 隐藏 Chrome/Safari 滚动条 */
}

.asset-category-tab {
	padding: 6px 14px;
	font-size: 12px;
	background-color: var(--light-gray-bg);
	color: #666;
	border-radius: 16px; /* 胶囊/药丸形状 */
	cursor: pointer;
	white-space: nowrap; /* 强制不换行 */
	transition: all 0.2s ease;
	border: 1px solid transparent;
	user-select: none;
}

.asset-category-tab:hover {
	background-color: var(--light-gray-hover);
}

.asset-category-tab.active {
	background-color: var(--primary-color-bg);
	color: var(--primary-color);
	border-color: var(--primary-color);
	font-weight: 600;
}

#btnDeleteAssetModal:hover {
	background: #fff1f0 !important;
}
.asset-edit-btn {
	position: absolute;
	top: -4px;
	right: -4px; /* 🌟 因为没有删除按钮挤占位置了，可以直接放到右上角死角 */
	width: 20px;
	height: 20px;
	background-color: #1890ff;
	color: white;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	cursor: pointer;
	opacity: 0;
	transition:
		opacity 0.2s,
		transform 0.2s;
	z-index: 10;
}

.asset-item:hover .asset-edit-btn {
	opacity: 1;
}

.asset-edit-btn:hover {
	background-color: #096dd9;
	transform: scale(1.1);
}

/* ===== Workspace ===== */
.workspace {
	flex: 1;
	height: 100%;
	background: #edf0f9;
	overflow: hidden;
	/* 核心：使用 Flex 布局让子元素垂直排列 */
	display: flex;
	flex-direction: column;
}

#viewport {
	flex: 1;
	width: 100%;
	cursor: default;
	position: relative;
	overflow: clip; /* 🌟 将 hidden 改为 clip，彻底阻断内部滚动 */
	touch-action: none;
}
#viewport.grabbing {
	cursor: grabbing !important;
}

#canvas {
	position: absolute;
	left: 0;
	box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
	transform-origin: 0 0;
	display: block;
	pointer-events: auto;
	overflow: clip; /* 🌟 将 hidden 改为 clip，彻底阻断内部滚动 */

	background-repeat: no-repeat;
	background-size: cover;
	background-color: #ffffff;
	--ui-scale: 1;
}

/* ===== Elements ===== */
.element {
	position: absolute;
	transform-origin: center center;
	user-select: none;
	cursor: move;
	box-sizing: border-box;
	touch-action: none;
}
.element.locked,
.element.image.locked,
.element.text.locked,
.element.shape.locked,
.element.group.locked {
	pointer-events: none !important;
	cursor: default !important;
}
.layer-lock-btn {
	margin-left: auto; /* 自动推到右边 */
	margin-right: 8px;
	cursor: pointer;
	opacity: 0.4;
	font-size: 14px;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
}
.layer-lock-btn:hover {
	opacity: 1;
}
.layer-lock-btn.is-locked {
	opacity: 1;
}
/* 锁定后，图层面板里的名字稍微变灰 */
.layer-item.locked .layer-name {
	opacity: 0.5;
}
.element.text {
	/* 允许自动换行，并保留代码中的 \n 换行符 */
	white-space: pre-wrap;
	overflow-wrap: break-word;
	word-wrap: break-word;
	word-break: normal;
	overflow: visible;
}

.element.image {
	pointer-events: auto !important;

	-webkit-user-drag: none;
}

.element.image img {
	width: 100%;
	height: auto;
	display: block;
	object-fit: contain; /* 确保图片完整显示且不失真 */
	pointer-events: none;
}
.setting-sidebar {
	width: 320px;
	display: flex;
	flex-direction: column;
	gap: 32px;
	position: relative;
	/* overflow-x: hidden; */
}
.add-btn-wrapper {
	display: flex;
	gap: 16px;
	padding-bottom: 16px;
}
.flex1 {
	flex: 1;
}
.secondary-btn {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 10px;
	border: 1px solid var(--light-gray-hover);
	border-radius: var(--radius-small);
	padding: 6px;
	font-size: 14px;
	cursor: pointer;
}
.secondary-btn:hover {
	background-color: var(--light-gray-hover);
}
.add-icon {
	width: 20px;
}
/* ===== Layers ===== */

#layers li {
	list-style: none;
	padding: 4px 0px;
	cursor: pointer;
	color: #5e5e5e;
}
.element.selected {
	outline: none !important;
}
#selection-overlay {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
	pointer-events: none; /* 让点击事件穿透到下方的 Canvas 元素 */
	z-index: 1000;
}
.selection-box {
	position: absolute;
	transform-origin: center center;
	outline: calc(2px / var(--ui-scale)) solid var(--primary-color);
	pointer-events: none;
	z-index: 1000;
}
.selection-box.secondary {
	/* 使用白色虚线和稍微的阴影使其在浅色或深色背景上都清晰可见 */
	outline: calc(2px / var(--ui-scale)) dashed var(--primary-color);

	pointer-events: none;
	z-index: 90;
	background-color: transparent;
}
/* 旋转控制点 */
.rotate-handle {
	position: absolute;
	/* 调整偏移量：原为 -24px，为了视觉平衡，建议根据新尺寸微调 */
	top: calc(-28px / var(--ui-scale));
	left: 50%;

	/* 修改大小：从 12px 增加到 16px，匹配 .scale-handle */
	width: calc(16px / var(--ui-scale));
	height: calc(16px / var(--ui-scale));

	background: var(--primary-color);
	border-radius: 50%;
	transform: translateX(-50%);
	cursor: grab;
	display: none;

	/* 增加白色边框，使其风格与缩放手柄更统一（可选） */
	border: calc(2px / var(--ui-scale)) solid #fff;
	box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
	background-clip: padding-box;
}

/* ===== 文字宽度调整手柄 (Width Handles) ===== */
.width-handle {
	position: absolute;
	width: calc(8px / var(--ui-scale));
	height: calc(24px / var(--ui-scale));
	background-color: #fff;
	border: calc(2px / var(--ui-scale)) solid var(--primary-color);
	border-radius: calc(4px / var(--ui-scale));
	z-index: 50;
	display: none; /* 默认隐藏 */
}

/* 左侧手柄 */
.width-handle.ml {
	left: calc(-5px / var(--ui-scale));
	top: 50%;
	transform: translateY(-50%);
	cursor: ew-resize;
}

/* 右侧手柄 */
.width-handle.mr {
	right: calc(-5px / var(--ui-scale));
	top: 50%;
	transform: translateY(-50%);
	cursor: ew-resize;
}

/* 当文字元素被选中时，显示该手柄 */
.selection-box .width-handle {
	display: block;
}
/* 手柄悬停缩放效果，注意保留原有的 translateY(-50%) */
.width-handle:hover {
	background-color: var(--primary-color);
	transform: translateY(-50%) scale(1.2);
	transition:
		transform 0.1s ease,
		background-color 0.1s ease;
}

/* ===== 文字高度调整手柄 (Height Handles) ===== */
.height-handle {
	position: absolute;
	/* 宽高正好与 width-handle 相反 */
	width: calc(24px / var(--ui-scale));
	height: calc(8px / var(--ui-scale));
	background-color: #fff;
	border: calc(2px / var(--ui-scale)) solid var(--primary-color);
	border-radius: calc(4px / var(--ui-scale));
	z-index: 50;
	display: none; /* 默认隐藏 */
}

/* 顶部手柄 */
.height-handle.mt {
	top: calc(-5px / var(--ui-scale));
	left: 50%;
	transform: translateX(-50%);
	cursor: ns-resize;
}

/* 底部手柄 */
.height-handle.mb {
	bottom: calc(-5px / var(--ui-scale));
	left: 50%;
	transform: translateX(-50%);
	cursor: ns-resize;
}

/* 当文字元素被选中时，显示该手柄 */
.selection-box .height-handle {
	display: block;
}

/* 手柄悬停效果，保留 translateX(-50%) 以防偏移 */
.height-handle:hover {
	background-color: var(--primary-color);
	transform: translateX(-50%) scale(1.2);
	transition:
		transform 0.1s ease,
		background-color 0.1s ease;
}

/* 确保移动端能触控 */
.selection-box .height-handle {
	pointer-events: auto;
}

.set-horizon-layout {
	display: flex;
	gap: 24px;
	align-items: center;
}
.input-wrapper {
	display: flex;
	align-items: center;
	flex: 1;
	gap: 8px;
	min-width: 0;
}
.input-wrapper label {
	width: 32px;
}
.input-wrapper input {
	flex: 1;
	min-width: 0;
}
.tool-bar {
	display: flex;
	justify-content: space-between;
	border-radius: var(--radius-small);
	margin-bottom: 8px;
}
.tool-icon {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 32px;
	height: 32px;
	border-radius: 4px;
	cursor: pointer;
}
.tool-icon:hover {
	background-color: var(--light-gray-hover);
}
.tool-icon.active {
	background-color: var(--medium-gray-bg);
}
.distribute {
	background-color: var(--light-gray-bg);
	display: flex;
	justify-content: center;
	gap: 6px;
	padding: 8px;
	flex: 1;
	border-radius: var(--radius-small);
	font-size: 14px;
	cursor: pointer;
}
.distribute:hover {
	background-color: var(--light-gray-hover);
}
/* 可以在层级树也体现多选 */
#layers li.active {
	background: var(--primary-color-bg);
	color: #1e1e1e;
}
/* 文字编辑状态样式 */
.element.text[contenteditable="true"] {
	outline: 2px dashed var(--primary-color);
	cursor: text;
	user-select: text; /* 允许选择文字内容 */
}

/* 隐藏旋转手柄和缩放手柄（如果有的话），避免编辑时干扰 */
.element.text[contenteditable="true"] .rotate-handle {
	display: none;
}

/* 缩放手柄 */
.resizer {
	position: absolute;
	width: 10px;
	height: 10px;
	background: #fff;
	border: 2px solid var(--primary-color);
	z-index: 10;
}

.resizer.rb {
	right: -5px;
	bottom: -5px;
	cursor: nwse-resize;
}

/* 选中图片时显示手柄 */
.element.selected .resizer {
	display: block;
}

/* 只有当父元素被选中时，才显示旋转手柄 */
.element.selected .rotate-handle {
	display: block; /* 新增：选中时显示 */
}
.element.selected .rotate-handle::after {
	content: "";
	position: absolute;
	height: calc(20px / var(--ui-scale));
	width: calc(1px / var(--ui-scale));
	background-color: var(--primary-color);
	left: 50%;
	bottom: -2px; /* 调整连接起点 */
	transform: translateX(-50%) translateY(100%);
	pointer-events: none;
	z-index: -1;
}

/* 镜像动画过渡 */
.element img {
	transition: transform 0.3s ease;
}

/* ===== 缩放手柄 (Scale Handles) 优化 ===== */

/* 1. 基础样式：移除固定的 right/bottom */
.scale-handle {
	position: absolute;
	width: calc(16px / var(--ui-scale));
	height: calc(16px / var(--ui-scale));
	background-color: #fff;
	border: calc(2px / var(--ui-scale)) solid var(--primary-color);
	border-radius: 50%;
	z-index: 101;
	display: none; /* 默认隐藏，选中时显示 */
}

/* 2. 四个角的位置定义与对应的缩放手势 */
.scale-handle.tl {
	top: calc(-8px / var(--ui-scale));
	left: calc(-8px / var(--ui-scale));
	cursor: nwse-resize;
}
.scale-handle.tr {
	top: calc(-8px / var(--ui-scale));
	right: calc(-8px / var(--ui-scale));
	cursor: nesw-resize;
}
.scale-handle.bl {
	bottom: calc(-8px / var(--ui-scale));
	left: calc(-8px / var(--ui-scale));
	cursor: nesw-resize;
}
.scale-handle.br {
	bottom: calc(-8px / var(--ui-scale));
	right: calc(-8px / var(--ui-scale));
	cursor: nwse-resize;
}

/* 3. 选中时显示所有手柄 */
.element.selected .scale-handle {
	display: block;
}

/* 增强触摸和悬停反馈 */
.scale-handle:hover {
	background-color: var(--primary-color);
	transform: scale(1.2);
	transition: transform 0.1s ease;
}

/* 4. 图片缩放时的容器调整 */
.element.image {
	/* 移除之前的 overflow: hidden 以便能看到超出边界的手柄 */
	overflow: visible !important;
}

/* 5. 确保图片填满缩放后的容器 */
.element.image img {
	width: 100%;
	height: 100%;
	object-fit: fill; /* 或者是 contain，取决于你是否允许拉伸 */
	display: block;
}

/* 模板外层容器 */
.template {
	border-radius: 4px;
	overflow: hidden;
	background: #5e5e5e;
	cursor: pointer;
	transition: all 0.2s ease;
	outline: 2px solid #f2f2f2;
}

.template:hover {
	box-shadow: 0 0 0 4px var(--primary-color);
}

.template.active {
	box-shadow: 0 0 0 4px var(--primary-color);
}
.thumbnail-wrapper {
	background: #5e5e5e;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
}
.thumbnail {
	width: 100%;
	height: 100%;
	object-fit: contain;
}
.template-name {
	display: none;
	padding: 6px;
	font-size: 12px;
	text-align: center;
	color: #333;
	background: #f2f1f5;
}

.export-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.6);
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	color: white;
	z-index: 9999;
}

.spinner {
	width: 40px;
	height: 40px;
	border: 4px solid #f3f3f3;
	border-top: 4px solid var(--primary-color);
	border-radius: 50%;
	animation: spin 1s linear infinite;
	margin-bottom: 10px;
}

@keyframes spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

#layers {
	display: flex;
	flex-direction: column;
	gap: 0px; /* 适当间距让位移动画更清晰 */
	position: relative;
}

.layer-item {
	font-size: 14px;
	display: flex;
	align-items: center;
	padding: 10px 14px;
	background: #fff;
	border-radius: 4px;
	margin-bottom: 4px;
	cursor: grab;
	/* 确保动画期间不会互相干扰 */
	will-change: transform;
	user-select: none;
}
.layer-item:hover {
	background: #f9f9f9;
}
.layer-item.active {
	border-color: var(--primary-color);
}

/* 正在被拖拽的元素：半透明并略微放大 */
/* 1. 浮起效果：用户按住图层时的状态 */
.layer-item.dragging {
	opacity: 0.8;
	transform: scale(1.04);
	box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
	z-index: 100;
	border-color: var(--primary-color);
	cursor: grabbing;
}

/* 目标放置位置的动态反馈：增加蓝色指示线 */
.layer-item.drag-over {
	background: #f0f7ff;
}

/* 拖拽时隐藏原位的虚影（可选，根据喜好决定） */
.layer-item.drag-ghost {
	opacity: 0;
}

.layer-type-icon {
	width: 16px;
	height: 16px;
	margin-right: 8px;
}
.layer-lock-btn .lock-icon {
	width: 16px;
	height: 16px;
	display: block;
	pointer-events: none; /* 防止图片本身拦截点击事件 */
}
.primary-btn {
	height: 34px;
	padding: 4px 16px;
	border-radius: var(--radius-small);
	background-color: var(--primary-color);
	display: flex;
	justify-content: center;
	align-items: center;
	color: white;
	gap: 8px;
	cursor: pointer;
	font-size: 14px;
}
.primary-btn:hover {
	background-color: var(--primary-hover-color);
}

.setting-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 12px;
}
.input-with-unit {
	display: flex;
	align-items: center;
	background: #f0f0f0;
	border-radius: 4px;
	padding: 0 8px;
}
.input-with-unit input {
	width: 50px;
	border: none;
	background: transparent;
	padding: 4px;
	text-align: right;
}
.unit {
	color: #999;
	font-size: 12px;
}

/* 导航栏图标按钮通用样式 */
.undo-redo-group {
	display: flex;
	align-items: center;
	gap: 8px;
	/* border-right: 1px solid #eee; */
}

.icon-btn {
	width: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 4px;
	cursor: pointer;
	color: #666;
	transition: all 0.2s;
}

.icon-btn:hover {
	background-color: var(--light-gray-hover);
	color: var(--primary-color);
}

.icon-btn:active {
	background-color: #e0e0e0;
}

/* 禁用状态（可选，如果栈为空时可以变淡） */
.icon-btn.disabled {
	color: #ccc !important;
	cursor: not-allowed !important;
	opacity: 0.4;
	pointer-events: none; /* 核心：防止点击 */
}

.layer-ctrl-icon {
	width: 16px;
}
.color-preview-box {
	width: 28px;
	height: 28px;
	border-radius: 4px;
	border: 1px solid #ddd;
	cursor: pointer;
	background: #ffffff;
}
.color-preview-box:hover {
	box-shadow: 0 0 0 2px var(--primary-color);
	border: none;
}

.color-popup {
	display: none; /* 默认隐藏 */
	position: fixed; /* 只有桌面端需要 fixed，JS 计算 top/left */
	width: 280px; /* 统一宽度 */
	background: #fff;
	z-index: 2000;
	border: 1px solid #ddd;
	border-radius: var(--radius-small);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	overflow: hidden;
	padding: 0;
}

.color-popup.active {
	display: block !important;
}

.popup-header {
	height: 32px;
	background: #f5f5f5;
	border-bottom: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 10px;
	cursor: grab; /* Drag cursor */
	font-size: 12px;
	font-weight: 600;
	color: #666;
	user-select: none;
}

.popup-header:active {
	cursor: grabbing;
}

.close-btn {
	cursor: pointer;
	display: flex;
	align-items: center;
	color: #999;
}
.close-btn:hover {
	color: #333;
}

/* New Body Style */
.popup-body {
	padding: 12px;
}
.color-tabs {
	display: flex;
	background-color: #f0f0f0;
	border-radius: var(--radius-small);
	gap: 8px;
	padding: 4px;
	margin-bottom: 8px;
}

.color-tab {
	flex: 1;
	text-align: center;
	padding: 1px 0;
	font-size: 14px;
	cursor: pointer;
	color: #5e5e5e;
	border-radius: var(--radius-small);
}

.color-tab.active {
	background-color: white;
	color: #000;
}

.tab-content {
	display: none;
}
.tab-content.active {
	display: block;
}
#iroColorPicker {
	display: flex;
	justify-content: center;
}
input[type="color"] {
	width: 40px;
}
/* 自定义色块样式 */
.color-swatch {
	width: 40px;
	height: 30px;
	border-radius: var(--radius-small);
	border: 2px solid #ddd;
	cursor: pointer;
	background-color: #fff;
	transition: all 0.2s;
	position: relative;
}

.color-swatch:hover {
	border-color: #999;
}

/* 激活状态：显示外发光或粗边框 */
.color-swatch.active {
	border-color: white;
	box-shadow: 0 0 0 2px #5e5e5e;
	/* 可以加一个小圆点指示器 */
}
.color-swatch.active::after {
	content: "";
	position: absolute;
	width: 6px;
	height: 6px;
	background: #fff;
	border-radius: 50%;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}

.snap-guide {
	position: absolute;
	background-color: #ff4d4f; /* 醒目的红色或蓝色 */
	pointer-events: none;
	z-index: 9999;
	display: none;
}
.snap-guide.horizontal {
	height: 1px;
	width: 100%;
	left: 0;
}
.snap-guide.vertical {
	width: 1px;
	height: 100%;
	top: 0;
}

/* 现代化的开关样式 */
.switch-toggle {
	position: relative;
	display: inline-block;
	width: 36px;
	height: 20px;
}
.switch-toggle input {
	opacity: 0;
	width: 0;
	height: 0;
}
.switch-toggle .slider {
	position: absolute;
	cursor: pointer;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: #ccc;
	transition: 0.4s;
	border-radius: 20px;
}
.switch-toggle .slider:before {
	position: absolute;
	content: "";
	height: 14px;
	width: 14px;
	left: 3px;
	bottom: 3px;
	background-color: white;
	transition: 0.4s;
	border-radius: 50%;
}
.switch-toggle input:checked + .slider {
	background-color: var(--primary-color);
}
.switch-toggle input:checked + .slider:before {
	transform: translateX(16px);
}
/* ===== 自定义字体选择器样式 ===== */

.custom-select-container {
	position: relative;
	width: 140px; /* 根据你的侧边栏宽度调整 */
	font-size: 13px;
	user-select: none;
}

/* 触发按钮 */
.select-trigger {
	flex: 1;
	display: flex;
	background-color: var(--light-gray-bg);
	padding: 6px;
	border-radius: var(--radius-small);
	cursor: pointer;
	height: 28px;
	align-items: center;
}

.select-trigger:hover {
	border-color: var(--primary-color);
}

.arrow {
	font-size: 10px;
	color: #999;
}

/* 下拉面板 */
.select-dropdown {
	display: none; /* 默认隐藏 */
	position: absolute;
	top: 100%;
	left: 0;
	width: 240px; /* 列表比按钮宽，方便展示预览图 */
	max-height: 300px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 6px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	z-index: 2000;
	margin-top: 4px;
	overflow: hidden;
	flex-direction: column;
}

.select-dropdown.open {
	display: flex;
}

/* 搜索框区域 */
.font-search-box {
	padding: 16px;
}

.font-search-box input {
	width: 100%;
	outline: none;
}

/* 列表滚动区域 */
.font-list-content {
	flex: 1;
	overflow-y: auto;
	padding: 0 16px 16px;
}

/* 单个字体选项 */
.font-item {
	display: flex;
	align-items: center;
	justify-content: flex-start; /* 改为左对齐 */
	padding: 10px 6px;
	cursor: pointer;
	gap: 6px; /* 使用 gap 控制内部元素间距 */
}

.font-item.expanded {
	top: 0;
	z-index: 10;
}
.font-item:hover {
	background-color: var(--light-gray-bg);
}

.font-item.active {
	background-color: var(--primary-color-bg);
}

/* 如果没有图片，用文字显示的备选样式 */
.font-text-preview {
	font-size: 16px;
}

/* 分类标题 (可选) */
.font-category-header {
	padding: 4px 12px;
	font-size: 11px;
	color: #999;
	background: #fcfcfc;
	font-weight: bold;
}

.snap-guide {
	position: absolute;
	background-color: #ff00ff; /* 使用显眼的洋红色 */
	z-index: 9999;
	pointer-events: none; /* 确保辅助线不干扰鼠标事件 */
	display: none;
}

#guide-h {
	left: 0;
	right: 0;
	height: 1px;
	transform: translateY(-0.5px);
}

#guide-v {
	top: 0;
	bottom: 0;
	width: 1px;
	transform: translateX(-0.5px);
}

/* 字体系列组容器 */
.font-family-group {
	border-bottom: 1px solid #f8f8f8;
}
.font-family-group:last-child {
	border-bottom: none;
}
/* 预览图尺寸限制 */
.font-preview-img {
	height: 20px;
	max-width: 200px;
	object-fit: contain;
	pointer-events: none;
}

/* 展开箭头 */
.variant-arrow {
	font-size: 12px;
	color: #999;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s ease;
	margin-left: 0; /* 移除之前的 auto */

	flex-shrink: 0; /* 防止图标被压缩 */
}
.font-item.expanded .variant-arrow {
	transform: rotate(180deg);
}
/* 变体列表 */
.variant-list {
	padding: 4px 0;
	overflow: hidden;
}

/* 变体选项 */
.variant-item {
	padding: 8px 12px 8px 40px;
	font-size: 16px;
	color: #666;
	cursor: pointer;
}

.variant-item:hover {
	background-color: var(--primary-color-bg);
	color: var(--primary-color);
}

.variant-item:last-child {
	border-bottom: none;
}

#sidebarMainView {
	height: 100%;
	padding: 16px 8px 16px 16px;
	box-sizing: border-box;
	font-size: 14px;
	display: flex;
	flex-direction: column;
	overflow-y: auto; /* 确保侧边栏本身是可以滚动的 */
	scrollbar-gutter: stable;
	overscroll-behavior: contain; /* 核心代码：防止滚动链传递到父级/Canvas */
}

.sidebar-sub-panel {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: #fff;
	z-index: 900;
	display: flex;
	flex-direction: column;
	display: none;
}

.sidebar-sub-panel.active {
	display: flex;
}

.sub-panel-header {
	display: flex;
	align-items: center;
	padding: 8px 16px;
	border-bottom: 1px solid #e0e0e0;
	background: #fff;
}

.font-content-wrapper {
	display: flex;
	align-items: center;
	overflow: hidden;
	justify-content: space-between;
	flex: 1;
}

.font-text-preview {
	white-space: nowrap;
}

/* Badge style for displaying weight on parent item */
.font-variant-badge {
	font-size: 12px;
	color: var(--primary-color);
	margin-left: 6px;
	white-space: nowrap;
}

/* ... (Existing variant styles) ... */

/* 变体选项 */
.variant-item {
	padding: 10px 12px 10px 40px;
	font-size: 14px; /* Slightly smaller than main */
	color: #666;
	cursor: pointer;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.variant-item:hover {
	background-color: var(--light-gray-bg);
}

/* 选中状态（如果需要高亮当前选中的字重） */
.variant-item.active {
	color: var(--primary-color);
	font-weight: 600;
}

/* Add a checkmark for active variant item */
.variant-item.active::after {
	content: "";
	display: block;
	width: 6px;
	height: 10px;
	border: solid var(--primary-color);
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
	margin-right: 4px;
}

/* ===== 字体加载 Loading 状态 ===== */
.font-item.loading,
.variant-item.loading {
	pointer-events: none; /* 加载中禁止再次点击 */
	opacity: 0.7;
	position: relative;
}

/* 在列表项右侧添加一个小圆圈动画 */
.font-item.loading::after,
.variant-item.loading::after {
	content: "";
	position: absolute;
	right: 10px;
	top: 50%;
	transform: translateY(-50%);
	width: 16px;
	height: 16px;
	border: 2px solid #f3f3f3;
	border-top: 2px solid var(--primary-color);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

section {
	padding: 16px 0;
	border-bottom: 1px solid #f0f0f0;
}

#opacityInput {
	cursor: pointer;
	accent-color: var(--primary-color); /* 使用主题色 */
}

.desktop-logo {
	display: block;
	height: 32px; /* Existing height */
}

/* 4. 手柄恢复指针事件以响应拖拽 */
.selection-box .rotate-handle,
.selection-box .scale-handle,
.selection-box .width-handle {
	display: block;
	pointer-events: auto;
}

/* 5. 旋转手柄的连接线 */
.selection-box .rotate-handle::after {
	content: "";
	position: absolute;
	height: calc(20px / var(--ui-scale));
	width: calc(1px / var(--ui-scale));
	background-color: var(--primary-color);
	left: 50%;
	bottom: -2px;
	transform: translateX(-50%) translateY(100%);
	pointer-events: none;
	z-index: -1;
}

/* ===== 运营大盘 Dashboard 样式 ===== */
.dashboard-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.6);
	z-index: 9999;
	display: flex;
	justify-content: center;
	align-items: center;
}
.dashboard-panel {
	background: #fff;
	width: 90vw;
	height: 90vh;
	border-radius: 8px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}
.table-wrapper {
	flex: 1;
	overflow: auto;
	width: 100%;
}
.dashboard-header {
	padding: 16px 24px;
	border-bottom: 1px solid #eee;
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #fdfdfd;
}

.admin-table {
	border-collapse: separate;
	border-spacing: 0;
	font-size: 13px;
	background: #fff;
	border-radius: 6px;
	width: 100%;
	min-width: max-content;
}
.admin-table th,
.admin-table td {
	border-bottom: 1px solid #f2f2f2;
	border-right: 1px solid #f2f2f2;
	padding: 8px;
	text-align: center;
	vertical-align: middle;
}
/* 🌟 固定第一列（缩略图列） */
.admin-table th:first-child,
.admin-table td:first-child {
	position: sticky;
	left: 0;
}

/* 保证表体第一列背景不透明，防止右侧内容滚动时穿透底色 */
.admin-table td:first-child,
.admin-table td:last-child {
	background: #fff;
	z-index: 5; /* 高于普通 td */
}

/* 表头第一列：必须同时吸顶和吸左，需要最高的层级 */
.admin-table th:first-child {
	background: #fafafa; /* 和你原有的表头背景色一致 */
	z-index: 20; /* 必须高于你之前设置的 th z-index: 10 */
}
.admin-table th:last-child,
.admin-table td:last-child {
	border-right: none;
	position: sticky;
	right: 0;
	/* 加一点点左侧阴影，盖住滚过来的内容 */
	box-shadow: -2px 0 5px -2px rgba(0, 0, 0, 0.1);
}
.admin-table tr:last-child td {
	border-bottom: none;
}
.admin-table th {
	background: #fafafa;
	position: sticky;
	top: 0;
	z-index: 10;
	font-weight: 600;
	color: #333;
}
input,
select,
textarea {
	box-sizing: border-box;
	padding: 6px;
	border-radius: 6px;
	transition: border 0.2s;
	background-color: var(--light-gray-bg);
	border: none;
	outline: none;
}
input:focus,
select:focus,
textarea:focus {
	background-color: var(--primary-color-bg);
	color: black;
}
input[type="checkbox"] {
	width: 18px;
	height: 18px;
	accent-color: var(--primary-color);
}
.admin-table img {
	max-width: 60px;
	max-height: 80px;
	object-fit: contain;
	border-radius: 4px;
}
.action-btn {
	padding: 6px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	color: white;
	font-size: 12px;
	transition: opacity 0.2s;
}
.save-row-btn {
	background: var(--primary-color);
	margin-bottom: 6px;
	width: 100%;
}
.save-row-btn:hover {
	opacity: 0.8;
}
.save-row-btn.success {
	background: #52c41a;
}
.del-row-btn {
	background: #ff4d4f;
	width: 100%;
}
.del-row-btn:hover {
	background: #ff7875;
}
.marquee-box {
	position: absolute;
	border: 1px solid var(--primary-color);
	background-color: rgba(136, 98, 207, 0.15); /* 主题色带透明度 */
	pointer-events: none; /* 确保不阻挡底层鼠标事件 */
	z-index: 9999;
}

/* ===== 管理员下拉菜单 ===== */
.admin-dropdown-container {
	position: relative;
	display: inline-block;
}

.admin-dropdown-menu {
	display: none;
	position: absolute;
	top: 100%;
	right: 0;
	margin-top: 8px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: var(--radius-small);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	min-width: 150px;
	z-index: 2000;
	flex-direction: column;
	overflow: hidden;
}

.admin-dropdown-menu.active {
	display: flex;
}

.admin-dropdown-item {
	padding: 10px 16px;
	font-size: 14px;
	color: #333;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 10px;
	transition: background-color 0.2s;
}

.admin-dropdown-item:hover {
	background-color: var(--light-gray-hover);
	color: var(--primary-color);
}

.admin-dropdown-item.danger {
	color: #ff4d4f;
	border-top: 1px solid #f0f0f0; /* 与上方操作隔开一点 */
}

.admin-dropdown-item.danger:hover {
	background-color: #fff1f0;
	color: #ff4d4f;
}
#viewport.drawing-mode,
#viewport.drawing-mode * {
	cursor: crosshair !important;
}
/* ===== 钢笔路径编辑隔离模式 ===== */
#viewport.path-editing-mode .element {
	/* 禁止其他所有元素响应鼠标/触控事件 */
	pointer-events: none !important;
}
#viewport.path-editing-mode .element.editing-path {
	/* 仅当前正在编辑的元素恢复响应，以接收控制杆的拖拽 */
	pointer-events: auto !important;
	/* 强制恢复光标，避免原本的拖拽手型造成误导 */
	cursor: default !important;
}
#viewport.path-editing-mode .selection-box {
	/* 隐藏所有的外边框，打造沉浸式纯净界面 */
	display: none !important;
}

.path-node {
	fill: #fff;
	stroke: var(--primary-color);
	cursor: pointer;
	transition: all 0.2s ease;

	/* 👇 修复 SVG 缩放位置偏移的关键两行 👇 */
	transform-origin: center;
	transform-box: fill-box;
}

/* 选中状态 */
.path-node.selected {
	fill: var(--primary-color);
	stroke: #fff;
	transform: scale(1.3);
	stroke-width: 3px;
}

/* 准备闭合时的吸附目标状态 */
.path-node.snap-target {
	stroke: #ff4d4f;
	stroke-width: 3px;
	transform: scale(1.3);
}

/* 描边位置按钮组样式 */
.stroke-pos-group {
	display: flex;
	background-color: var(--light-gray-bg);
	border-radius: var(--radius-small);
	padding: 2px;
	flex: 1;
}

.stroke-pos-btn {
	flex: 1;
	border: none;
	background: transparent;
	color: #666;
	font-size: 12px;
	padding: 4px 0;
	cursor: pointer;
	border-radius: 4px;
	transition: all 0.2s ease;
}

.stroke-pos-btn:hover {
	color: #333;
}

.stroke-pos-btn.active {
	background-color: #ffffff;
	color: var(--primary-color);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
	font-weight: bold;
}

.stroke-style-btn {
	flex: 1;
	border: none;
	background: transparent;
	color: #666;
	font-size: 14px;
	padding: 4px 0;
	cursor: pointer;
	border-radius: 4px;
	transition: all 0.2s ease;
}

.stroke-style-btn:hover {
	color: #333;
}

.stroke-style-btn.active {
	background-color: #ffffff;
	color: var(--primary-color);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
	font-weight: bold;
}

.grad-bar-track {
	position: relative;
	height: 16px;
	border-radius: 8px;
	background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYSm/YfAAAAABJRU5ErkJggg==");
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
	cursor: crosshair;
	margin: 8px 4px;
}
.grad-bar-bg {
	position: absolute;
	width: 100%;
	height: 100%;
	border-radius: 8px;
	pointer-events: none;
}
.grad-stop {
	position: absolute;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	border: 2px solid #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
	top: 50%;
	transform: translate(-50%, -50%);
	cursor: grab;
	z-index: 10;
}
.grad-stop:active {
	cursor: grabbing;
}
.grad-stop.active {
	border-color: var(--primary-color);
	box-shadow:
		0 0 0 2px rgba(136, 98, 207, 0.3),
		0 1px 3px rgba(0, 0, 0, 0.3);
	z-index: 11;
}
#mobile-blocker {
	display: none;
}

/* 当屏幕宽度小于等于 768px 时触发拦截 */
@media (max-width: 768px) {
	/* 强制隐藏所有主界面元素（加上 !important 防止被其他样式覆盖） */
	.navbar,
	.app,
	.export-overlay,
	.dashboard-overlay,
	#colorPickerPopup {
		display: none !important;
	}

	/* 全屏显示拦截提示 */
	#mobile-blocker {
		display: flex;
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background-color: var(--light-gray-bg, #f8f8f8);
		z-index: 99999;
		justify-content: center;
		align-items: center;
		text-align: center;
		padding: 20px;
	}

	/* 提示卡片的美化 */
	.blocker-content {
		background: #ffffff;
		padding: 40px 30px;
		border-radius: 8px;
		max-width: 320px;
		width: 100%;
	}

	.blocker-content h2 {
		margin: 0 0 12px;
		color: #333333;
		font-size: 20px;
	}

	.blocker-content p {
		margin: 0;
		color: #666666;
		font-size: 14px;
		line-height: 1.6;
	}
}

/* ===== 自定义右键菜单 (Context Menu) ===== */
.context-menu {
	position: fixed;
	background: #ffffff;
	border: 1px solid #e0e0e0;
	border-radius: var(--radius-small, 6px);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
	padding: 6px 0;
	min-width: 180px;
	z-index: 10000; /* 确保层级在最上面 */
	font-size: 13px;
	color: #333;
	user-select: none;
}
.context-menu-item {
	padding: 8px 16px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	cursor: pointer;
	transition: background-color 0.15s;
}
.context-menu-item:hover {
	background-color: var(--primary-color-bg, #f9f5ff);
	color: var(--primary-color, #8862cf);
}
.context-menu-item.disabled {
	color: #ccc;
	cursor: not-allowed;
}
.context-menu-item.disabled:hover {
	background-color: transparent;
	color: #ccc;
}
.context-menu-separator {
	height: 1px;
	background-color: #f0f0f0;
	margin: 6px 0;
}
.context-menu-item .shortcut {
	color: #999;
	font-size: 11px;
}
