body {
  text-align: center;
}
img {
  width: 300px;
}
.character {
  position: relative;
  width: 300px;
  height: 600px;
  margin: 0 auto;
}
.character img {
  position: absolute;
  width: 300px;
  left: 0;
  top: 0;
}
.character img {
  pointer-events: none;
}
.controls {
  position: relative;
  z-index: 10;
}
.front-controls {
  margin-top: 430px;
}
#sideHairTop {
  display: none;
}
.tie-hair {
  position: absolute;
  width: 300px;
  left: 0;
  top: 0;
  z-index: 2;
}
.character .tie-hair {
  pointer-events: auto;
}
/* 髪・顔・土台の重なり順 */
#backHair { z-index: 1; }
#base { z-index: 2; }
#faceBase { z-index: 3; }
#eyelashes { z-index: 4; }
#eyes { z-index: 5; }
#eyebrows { z-index: 6; }
#mouth { z-index: 7; }
#sideHair { z-index: 8; }
#frontHair { z-index: 9; }
#sideHairTop { z-index: 10; }
#trashCan {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 50px;
  z-index: 100;
}

/* 顔パーツ */
#faceBase {
  z-index: 20;
}

#eyebrows {
  z-index: 21;
}

#eyes {
  z-index: 22;
}

#eyelashes {
  z-index: 23;
}

#mouth {
  z-index: 24;
}
#tops {
  z-index: 11;
}
#eyebrows {
  display: block;
  z-index: 30;
}
/* レイヤー順：数字が大きいほど手前 */

#shoes { z-index: 22; }
#socks { z-index: 21; }
#head { z-index: 20; }
#neck { z-index: 19; }
#hand { z-index: 18; }
#other { z-index: 17; }

#collar { z-index: 16; }
#outer { z-index: 15; }
#tops { z-index: 14; }
#sleeve { z-index: 13; }
#bottoms { z-index: 12; }

#frontHair { z-index: 11; }
#sideHair { z-index: 10; }

#mouth { z-index: 9; }
#eyebrows { z-index: 8; }
#faceBase { z-index: 7; }
#eyelashes { z-index: 6; }
#eyes { z-index: 5; }

#base { z-index: 4; }
#tieHair { z-index: 3; }
#backHair { z-index: 2; }
#back { z-index: 1; }
/* サイド髪②だけ前髪より手前に表示 */
#sideHairTop {
  z-index: 12;
}

#collar { z-index: 16; }
#outer { z-index: 15; }
#tops { z-index: 14; }
#sleeve { z-index: 13; }
#bottoms { z-index: 12; }
/* 服より髪を手前にする */
#frontHair {
  z-index: 18;
}

#sideHair {
  z-index: 17;
}

#collar {
  z-index: 16;
}

#outer {
  z-index: 15;
}

#tops {
  z-index: 14;
}

#sleeve {
  z-index: 13;
}

#bottoms {
  z-index: 12;
}

/* サイド髪②は前髪より手前 */
#sideHairTop {
  z-index: 25;
}
/* 服は最初は非表示 */
#collar,
#outer,
#tops,
#sleeve,
#bottoms {
  display: none;
}

/* 装飾は最初は非表示 */
#itemBack,
#itemHead,
#itemNeck,
#itemHand,
#itemSocks,
#itemShoes,
#itemOther {
  display: none;
}

/* 装飾のレイヤー順 */
#itemBack { z-index: 1; }
#itemOther { z-index: 17; }
#itemHand { z-index: 18; }
#itemNeck { z-index: 19; }
#itemHead { z-index: 20; }
#itemSocks { z-index: 21; }
#itemShoes { z-index: 22; }
/* 装飾・服のレイヤー順を調整 */
#itemOther {
  z-index: 30;
  position: absolute;
}

#itemShoes { z-index: 11; }
#itemSocks { z-index: 10; }
.character .other-item {
  pointer-events: auto;
  touch-action: none;
}
/* サイト全体 */
.app {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  box-sizing: border-box;
}

/* タイトル */
.app h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.intro {
  margin: 0 0 12px;
  font-size: 14px;
}

/* キャラクター表示エリア */
.workspace {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

/* キャラクターを置く場所 */
.character-area {
  position: relative;
  width: 100%;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* タブレット画面向け */
@media (min-width: 600px) {
  .character-area {
    min-height: 0;
  }
}
#finishButton {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 100px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 100;
}

#finishButton img {
  display: block;
  width: 100%;
  height: auto;
}
/* 着せ替え画面のレイアウト */
.studio {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  box-sizing: border-box;
}

/* パーツ選択エリア */
.parts-panel {
  flex: 1;
  min-width: 0;
max-width: none;
  padding: 20px;
  box-sizing: border-box;
  background: #fff8fc;
  border: 2px solid #f3ddec;
  border-radius: 20px;
}

/* パーツ選択欄 */
.parts-panel .controls {
  margin: 12px 0;
  padding: 12px;
  background: #ffffff;
  border-radius: 12px;
}

/* 見出し */
.parts-panel .controls p {
  margin: 0 0 10px;
  font-weight: bold;
  color: #765675;
}

/* パーツ選択ボタン */
.parts-panel .controls button {
  margin: 3px;
  padding: 8px 12px;
  border: 1px solid #e5c5dc;
  border-radius: 10px;
  background: #fff0f7;
  cursor: pointer;
}

/* 画面が狭い場合 */
@media (max-width: 800px) {
  .studio {
    flex-direction: column;
    align-items: center;
  }

  .parts-panel {
    width: 100%;
  }
}
/* カテゴリー画像：横スクロール */
.category-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px;
  margin-bottom: 12px;
}

.category-button {
  flex: 0 0 76px;
  height: 76px;
  padding: 4px;
  border: 2px solid #e5c5dc;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}

.category-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* パーツ画像：下方向にスクロール */
.part-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
}

.part-button {
  min-width: 0;
  aspect-ratio: 1;
  padding: 4px;
  border: 1px solid #e5c5dc;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.part-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.category-button:focus,
.part-button:focus {
  outline: 3px solid #d69bc0;
}
/* パーツ欄をキャラクターの下の余白へ移動 */
.parts-panel {
  margin-top: -200px;
  position: relative;
  z-index: 5;
}
/* キャラクター周辺の余白を調整 */
.studio {
  gap: 0;
}

.character-area {
  margin-top: 0;
  padding-top: 0;
}
/* ページ上部の余白を減らす */
body {
  margin-top: 0;
  padding-top: 0;
}

main {
  margin-top: 0;
  padding-top: 0;
}
/* 左右反転ボタン */
#flipButton {
  position: fixed;
  top: 100px;
  right: 20px;
  width: 100px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 100;
}

#flipButton img {
  display: block;
  width: 100%;
  height: auto;
}

/* ゴミ箱ボタン */
#trashCan {
  display: none;
  position: fixed;
  top: 180px;
  right: 20px;
  bottom: auto;
  left: auto;
  transform: none;
  width: 100px;
  z-index: 100;
  cursor: pointer;
}

#trashCan img {
  display: block;
  width: 100%;
  height: auto;
}