* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: #fff0f5;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* 移动端主容器：锁定绝对定位基准，柔和圆润 */
.game-container {
  width: 100%;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 24px rgba(255, 182, 193, 0.3);
}

/* 【修正】：顶部插画风导航栏，宽厚圆润，保存按钮精准靠右 */
.top-bar {
  width: 100%;
  height: 60px;
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
  display: flex;
  justify-content: flex-end; /* 让内部元素靠右对齐 */
  align-items: center;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255, 154, 158, 0.25);
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  z-index: 100;
}

.save-btn {
  background: #ffffff;
  color: #ff6b8b;
  border: none;
  padding: 8px 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.save-btn:active {
  transform: scale(0.92);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 1. 上半部分：人物画布区域 */
.canvas-box {
  position: relative;
  width: 100%;
  height: 48vh;
  flex-shrink: 0;
  background-color: #fff5f7;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* 内部 1:1 正方形换装画布（专属透明棋盘格） */
#avatarCanvas {
  width: 100%;
  max-width: 46vh;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  background-color: #ffffff;
  background-image: 
    linear-gradient(45deg, #f2f2f2 25%, transparent 25%), 
    linear-gradient(-45deg, #f2f2f2 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #f2f2f2 75%), 
    linear-gradient(-45deg, transparent 75%, #f2f2f2 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border-radius: 16px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.accessory-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 46vh;
  aspect-ratio: 1 / 1;
  pointer-events: none;
}

/* 自由饰品容器 */
.draggable-acc {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
  touch-action: none;
  box-sizing: border-box;
}

.draggable-acc.active-edit {
  pointer-events: auto;
  cursor: move;
  border: 3px dashed #ff758c;
  border-radius: 16px;
}

.draggable-acc img {
  display: block;
  max-width: 50vw;
  max-height: 40vh;
  object-fit: contain;
  pointer-events: auto;
  cursor: pointer;
}

.draggable-acc .delete-badge {
  display: none;
  position: absolute;
  top: -12px;
  right: -12px;
  width: 30px;
  height: 30px;
  background-color: #ff5252;
  color: #ffffff;
  border-radius: 50%;
  font-size: 15px;
  font-weight: bold;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(255, 82, 82, 0.4);
  z-index: 20;
  pointer-events: auto;
}

.draggable-acc.active-edit .delete-badge {
  display: flex;
}

/* 饰品操作悬浮栏 */
.acc-controls {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(255, 182, 193, 0.4);
  backdrop-filter: blur(4px);
  z-index: 90;
}

.acc-controls button {
  background: #fff0f3;
  color: #d63384;
  border: none;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.acc-controls button:active {
  background: #ffd6e0;
}

.acc-controls .del-btn {
  background: #ffe3e6;
  color: #ff4d4f;
}

/* 中间：分类 Tab 图标栏（无边框，插画卡片风） */
.category-tabs {
  display: flex;
  overflow-x: auto;
  background: #fff5f7;
  padding: 12px 16px;
  gap: 14px;
  scrollbar-width: none;
  flex-shrink: 0;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.tab-item {
  width: 60px;
  height: 60px;
  min-width: 60px;
  padding: 0 !important;
  border: none;
  border-radius: 20px;
  background: #ffffff;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 4px 10px rgba(255, 182, 193, 0.25);
}

.tab-item.active {
  background: #ffe4ec;
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 6px 16px rgba(255, 117, 140, 0.4);
}

.category-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 2. 下半部分：服装选择网格（厚重可爱的插画风色调） */
.item-grid {
  height: 42vh;
  background: linear-gradient(180deg, #fff9fb 0%, #ffeef3 100%);
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  overflow-y: auto;
  align-content: start;
}

.item-card {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  overflow: hidden;
  box-sizing: border-box;
  border: none;
  cursor: pointer;
  background-color: #ffffff;
  padding: 6px;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 4px 12px rgba(255, 182, 193, 0.2);
}

.item-card:hover {
  transform: translateY(-2px);
}

.item-card.active {
  background-color: #ffe4ec;
  box-shadow: 0 6px 18px rgba(255, 117, 140, 0.35);
  transform: scale(1.03);
}

.item-img-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.item-img-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  box-sizing: border-box;
  display: block;
}

.item-card p {
  display: none;
}