/* 试衣间额外变量（颜色主体沿用 theme.css） */
:root {
  --hover-bg: #1a2030;
  --active-bg: #6ea8fe;
  --active-fg: #0f1115;
  --danger: #ff6b6b;
}
:root[data-theme="deepgray"] {
  --hover-bg: #4a4850;
  --active-bg: #8ab4f8;
  --active-fg: #1f2328;
  --danger: #f28b82;
}
:root[data-theme="ash"] {
  --hover-bg: #d4d7d9;
  --active-bg: #0b57d0;
  --active-fg: #ffffff;
  --danger: #c5221f;
}
:root[data-theme="white"] {
  --hover-bg: #e0e4e8;
  --active-bg: #2563eb;
  --active-fg: #ffffff;
  --danger: #dc3545;
}

/* 基础样式（覆盖 theme.css 的 body，保证试衣间全屏布局） */
html, body {
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overscroll-behavior: none;
}
body {
  display: flex;
  flex-direction: column;
}

/* 全局斜向水印：超大网格旋转后铺满全屏/画布 */
.global-watermark {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
}
.global-watermark-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  /* 旋转 45° 后对角线需覆盖视口，边长取更大值 */
  width: max(300vw, 300vh);
  height: max(300vw, 300vh);
  transform: translate(-50%, -50%) rotate(-45deg);
  display: grid;
  gap: 0;
  opacity: 0.16;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.2;
}
.global-watermark-layer span {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  padding: 9px 5px;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left h1 {
  margin: 0;
}

/* 顶部栏 */
header {
  position: relative;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  flex-shrink: 0;
  z-index: 20;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 100%;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 标题栏方形双行按钮（肤色 / 主题，样式完全一致） */
.theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 52px;
  min-height: 52px;
  padding: 6px 8px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  color: var(--fg);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.15;
  transition: all 0.2s;
  box-sizing: border-box;
}

.theme-btn:hover {
  background: var(--hover-bg);
}

.theme-btn b {
  font-size: 13px;
  font-weight: 700;
}

/* 主容器 */
.main-container {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  gap: 0;
  position: relative;
}

.main-container.layout-row {
  flex-direction: row;
}

.main-container.layout-col {
  flex-direction: column;
}

/* 可拖动的分隔条 */
.resizer {
  width: 10px;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
  user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.resizer::before {
  content: '';
  position: absolute;
  inset: 0;
  /* 扩大可拖区域 */
}

.main-container.layout-row .resizer::before {
  left: -8px;
  right: -8px;
}

.main-container.layout-col .resizer {
  width: 100%;
  height: 18px;
  cursor: row-resize;
}

.main-container.layout-col .resizer::before {
  top: -8px;
  bottom: -8px;
}

.resizer:hover,
.resizer.dragging {
  background: var(--acc);
}

.resizer-snap-btn {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--fg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  flex-shrink: 0;
}

.resizer-snap-btn:hover {
  background: var(--hover-bg);
  border-color: var(--acc);
  color: var(--acc);
}

.main-container.layout-col .resizer-snap-btn {
  width: 36px;
  height: 22px;
  font-size: 14px;
}

/* 左侧/上方画布区域 */
.canvas-section {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--stage);
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.canvas-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.control-btn {
  padding: 8px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  color: var(--fg);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}

.control-btn:hover {
  background: var(--hover-bg);
}

.control-btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.control-btn.danger:hover {
  opacity: 0.9;
}

.canvas-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--stage);
}

.canvas-wrapper:active {
  cursor: grabbing;
}

canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  /* 宽高由 JS 设置；拖分隔条时锁定尺寸，避免每帧重设导致抖动缩放 */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 右侧/底部服装部件区域 */
.parts-section {
  width: 66.67%; /* 默认占 2/3 宽度 */
  min-width: 120px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  overflow: hidden;
  flex: 0 0 auto;
  touch-action: pan-y;
  transition: width 0.2s ease, height 0.2s ease, min-width 0.2s ease, min-height 0.2s ease;
}

.main-container.layout-row .canvas-section {
  flex: 1 1 auto;
  min-width: 120px;
}

.main-container.layout-col .canvas-section {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  min-height: 140px;
}

.main-container.layout-col .parts-section {
  width: 100% !important;
  min-width: 0;
  max-width: none;
  flex: 0 0 auto;
  min-height: 140px;
  max-height: 70%;
}

.main-container.parts-collapsed.layout-row .parts-section {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden;
}

.main-container.parts-collapsed.layout-col .parts-section {
  height: 0 !important;
  min-height: 0 !important;
  max-height: none;
  overflow: hidden;
}

.main-container.parts-collapsed .parts-section > * {
  visibility: hidden;
}

/* 竖屏时分隔条始终可点（即使部件区收起） */
.main-container.layout-col .resizer {
  flex: 0 0 18px;
}

/* 搜索框 */
.search-box {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

#partSearch {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#partSearch:focus {
  border-color: var(--acc);
}

/* 标签页 */
.tabs-container {
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  padding: 0 16px;
  gap: 4px;
  min-width: max-content;
}

.tab-btn {
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--fg);
  background: var(--hover-bg);
}

.tab-btn.active {
  color: var(--acc);
  border-bottom-color: var(--acc);
}

/* 服装部件列表 */
.parts-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px 12px;
  align-items: start;
}

/* 注意：.part-item 这个类名在 theme.css 里已经被"图鉴主页-查看部件"面板占用
   (固定 100x100px、自带背景边框)。这里必须加上 .parts-grid 前缀提高选择器权重，
   避免两处样式互相覆盖导致方框叠加、名字被压扁等问题。 */
.parts-grid .part-item {
  position: static;
  width: auto;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 0;
  flex-shrink: 1;
}

.parts-grid .part-item:hover .part-image-wrapper {
  border-color: var(--acc);
  background: color-mix(in oklab, var(--stage) 85%, var(--acc) 15%);
}

.parts-grid .part-item.selected .part-image-wrapper {
  background: color-mix(in oklab, var(--stage) 72%, var(--acc) 28%);
  border-color: var(--acc);
  outline: 2px solid var(--acc);
  outline-offset: 2px;
}

.parts-grid .part-item.selected .part-name {
  color: var(--fg);
  font-weight: 600;
  border-color: var(--acc);
}

/* 预览图：始终正方形（配色/形状参考图鉴主页的部件图标） */
.parts-grid .part-image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  flex: 0 0 auto;
  background: var(--stage);
  border: 2px solid var(--btn-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
  box-sizing: border-box;
}

.parts-grid .part-image {
  width: 90%;
  height: 90%;
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
  pointer-events: none;
}

/* 散件标签 */
.single-cloth-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: #FF9800;
  color: white;
  font-size: 11px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

/* 部件名：向上叠在方框底部的小标签（参考图鉴主页部件图标的名字样式，略微覆盖图标框） */
.parts-grid .part-name {
  position: relative;
  z-index: 2;
  margin: -12px 0 0;
  padding: 2px 10px;
  font-size: var(--part-name-font-size);
  text-align: center;
  color: var(--fg);
  line-height: 1.4;
  height: auto;
  min-height: 0;
  /* 两边留宽一点，且允许比图标方框略宽，保证窄屏下也能完整显示 6 个字 */
  max-width: max(92%, calc(6.5em + 20px));
  box-sizing: border-box;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-badge {
  display: inline-block;
  background: var(--acc);
  color: white;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  font-weight: bold;
  vertical-align: middle;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.no-parts {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* 分页控制 */
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.page-btn {
  padding: 8px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  color: var(--fg);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
  background: var(--hover-bg);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
}

#pageInput {
  width: 60px;
  padding: 6px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  text-align: center;
  font-size: 13px;
  outline: none;
}

#pageInput:focus {
  border-color: var(--acc);
}

/* 已穿戴部件抽屉：默认贴在左边缘，只露出箭头，点击后整体向右滑出
   --equipped-icon-size 由 JS 实时同步为右侧部件网格图标的实际渲染尺寸，
   保证抽屉里的图标始终和右边试衣间部件列表的图标一样大；
   --part-name-font-size 统一控制左侧抽屉和右侧部件列表的名字字号，两边始终保持一致 */
:root {
  --equipped-icon-size: 100px;
  --part-name-font-size: 12px;
}

.equipped-panel {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translate(-100%, -50%);
  /* em 需要和 .equipped-name 用同一套字号做基准，这里显式对齐，避免两处 em 换算不一致 */
  font-size: var(--part-name-font-size);
  /* 抽屉宽度要跟得上名字标签（允许比图标略宽）的最大宽度，避免窄屏下名字被裁切 */
  width: calc(max(var(--equipped-icon-size), calc(6.5em + 20px)) + 18px);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
  z-index: 500;
  transition: transform 0.28s ease, width 0.2s ease;
}

.equipped-panel.open {
  transform: translate(0, -50%);
}

.equipped-panel-list {
  flex: 1;
  overflow-y: auto;
  min-height: 64px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.equipped-panel-toggle {
  position: absolute;
  top: 50%;
  right: -26px;
  transform: translateY(-50%);
  width: 26px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--btn-bg);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.15);
  transition: background 0.2s;
}

.equipped-panel-toggle:hover {
  background: var(--hover-bg);
}

.equipped-panel-arrow {
  display: inline-block;
  line-height: 1;
  transition: transform 0.28s ease;
}

.equipped-panel.open .equipped-panel-arrow {
  transform: rotate(180deg);
}

.equipped-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

/* 图标方框：尺寸与配色都和右侧 .parts-grid .part-image-wrapper 保持一致 */
.equipped-image-wrapper {
  position: relative;
  width: var(--equipped-icon-size);
  height: var(--equipped-icon-size);
  flex: 0 0 auto;
  background: var(--stage);
  border: 2px solid var(--btn-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
  transition: width 0.2s ease, height 0.2s ease;
}

.equipped-image {
  width: 90%;
  height: 90%;
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.equipped-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 3;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s;
}

.equipped-remove-btn:hover {
  opacity: 0.85;
}

/* 部件名：样式和覆盖方式与右侧 .parts-grid .part-name 完全一致 */
.equipped-name {
  position: relative;
  z-index: 2;
  margin: -12px 0 0;
  padding: 2px 10px;
  font-size: var(--part-name-font-size);
  text-align: center;
  color: var(--fg);
  line-height: 1.4;
  /* 两边留宽一点，且允许比图标方框略宽，保证窄屏下也能完整显示 6 个字 */
  max-width: max(92%, calc(6.5em + 20px));
  box-sizing: border-box;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.equipped-empty {
  padding: 14px 4px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

/* 窄屏细节（布局方向由 JS 的 layout-row/layout-col 控制） */
@media (max-width: 768px) {
  :root {
    --part-name-font-size: 9px;
  }

  .parts-grid {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
  }

  .parts-grid .part-name,
  .equipped-name {
    margin-top: -9px;
  }

  h1 {
    font-size: 16px;
  }

  .canvas-controls {
    top: 8px;
    right: 8px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - 16px);
  }

  .control-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .search-box {
    padding: 10px 12px;
  }

  .pagination-controls {
    padding: 10px 12px;
    flex-wrap: wrap;
  }

  .equipped-panel {
    max-height: 74vh;
  }

  .equipped-panel-toggle {
    width: 22px;
    height: 44px;
    right: -22px;
    font-size: 13px;
  }
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--input-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
