/* 画布基础 */
#canvasWrapper,
#mobileCanvasWrapper {
  width: 100%;
  max-width: 900px;
}

#canvas,
#mobileCanvas {
  width: 2000px;
  transform-origin: top left;
  box-sizing: border-box;
  padding: 20px;
}

/* 根据容器宽度自动缩放 */
#canvasWrapper,
#mobileCanvasWrapper {
  overflow: hidden;
}

/* 宋体回退栈 */
.caption {
  font-family: "SimSun", "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: 24px;
  line-height: 1.6;
}

/* 素材库项 */
.material-item {
  cursor: grab;
  transition: all 0.15s;
}
.material-item:active {
  cursor: grabbing;
}
.material-item.dragging {
  opacity: 0.5;
}

/* 画布网格项 */
.canvas-cell {
  position: relative;
  transition: box-shadow 0.15s;
}
.canvas-cell:hover {
  box-shadow: 0 0 0 2px #3b82f6;
}
.canvas-cell.selected {
  box-shadow: 0 0 0 3px #2563eb;
}

/* 图片容器 */
.img-wrap {
  position: relative;
  overflow: hidden;
  background: #f3f4f6;
}
.img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 边框样式 */
.with-border .img-wrap {
  border: var(--border-width, 2px) solid #374151;
}
.with-border .caption {
  border-left: var(--border-width, 2px) solid #374151;
  border-right: var(--border-width, 2px) solid #374151;
  border-bottom: var(--border-width, 2px) solid #374151;
  margin-top: -1px;
}

/* 空位占位符 */
.empty-cell {
  background: repeating-linear-gradient(
    45deg,
    #f9fafb,
    #f9fafb 10px,
    #f3f4f6 10px,
    #f3f4f6 20px
  );
  border: 2px dashed #d1d5db;
}

/* 拖拽占位符 */
.drop-target {
  outline: 2px dashed #3b82f6;
  outline-offset: -2px;
  background: rgba(59, 130, 246, 0.05);
}

/* 裁剪弹层 */
#cropperModal {
  display: none;
}
#cropperModal.active {
  display: flex;
}

/* 导出弹层 */
#exportModal {
  display: none;
}
#exportModal.active {
  display: flex;
}

/* 比例按钮高亮 */
.ratio-btn.active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

/* 缩放滑块 */
#zoomSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
}
#zoomSlider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: none;
}

/* 隐藏滚动条 */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* =================== 移动端布局 =================== */
.mobile-layout {
  display: none !important;
}

/* 移动端标签栏 */
.mobile-tabs {
  display: none;
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}
.mobile-tab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 14px;
  color: #6b7280;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.mobile-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 500;
}

/* 移动端面板 */
.mobile-panel {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}
.mobile-panel.active {
  display: flex;
}

/* 移动端画布区域 */
.mobile-canvas-area {
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* 移动端素材列表 */
.mobile-material-header {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 14px;
  font-weight: 500;
  color: #4b5563;
  background: #fff;
}
.mobile-material-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  background: #fff;
}

/* 移动端素材项 */
.mobile-material-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 8px;
}
.mobile-material-item img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: #e5e7eb;
}
.mobile-material-item .info {
  flex: 1;
  min-width: 0;
}
.mobile-material-item .name {
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-material-item .meta {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}
.mobile-material-item .btn-remove {
  padding: 6px 10px;
  font-size: 12px;
  color: #ef4444;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
}
.mobile-material-item .btn-add {
  padding: 6px 10px;
  font-size: 12px;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
}

/* 移动端设置面板 */
.mobile-settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fff;
}

/* 移动端画布单元格点击态 */
.mobile-canvas-area .canvas-cell {
  cursor: pointer;
}

/* =================== 响应式断点 =================== */

/* 平板微调 */
@media (max-width: 1280px) {
  aside.w-56 { width: 200px; }
  aside.w-64 { width: 220px; }
}

@media (max-width: 1024px) {
  aside.w-56 { width: 180px; }
  aside.w-64 { width: 200px; }
  #toolbar {
    gap: 6px;
  }
}

/* 手机端 */
@media (max-width: 768px) {
  .desktop-layout,
  .desktop-only {
    display: none !important;
  }
  .mobile-layout {
    display: flex !important;
  }
  .mobile-tabs {
    display: flex;
  }

  /* 顶部工具栏优化 */
  #mainHeader {
    padding: 8px 12px;
    flex-wrap: nowrap;
  }
  #mainHeader h1 {
    font-size: 15px;
  }
  #toolbar {
    gap: 6px;
    padding-left: 4px;
  }
  #toolbar button,
  #toolbar select,
  #toolbar label {
    font-size: 12px;
    padding: 6px 10px;
  }
  #customGrid input {
    width: 36px;
    font-size: 12px;
  }
  #globalFontSize {
    width: 44px !important;
    font-size: 12px;
  }

  /* 裁剪弹层手机适配 */
  #cropperModal > div {
    width: 96vw;
    max-height: 85vh;
  }
  #cropperModal .flex.gap-2.flex-wrap {
    flex-wrap: wrap;
    gap: 4px;
  }

  /* 导出弹层手机适配 */
  #exportModal > div {
    width: 96vw;
  }
}

/* 小屏手机额外优化 */
@media (max-width: 380px) {
  #mainHeader h1 {
    font-size: 13px;
  }
  #toolbar button,
  #toolbar select {
    padding: 5px 8px;
    font-size: 11px;
  }
}

/* 微信内置浏览器特殊优化 */
.wechat-browser .mobile-canvas-area {
  -webkit-overflow-scrolling: touch;
}
.wechat-browser #exportPreview img {
  max-width: 100%;
  height: auto;
}
