body { font-family: sans-serif; text-align: center; }
.controls { margin: 20px; }
.thumbnails {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}
.thumbnail {
  width: 64px;
  height: 64px;
  margin: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  box-sizing: border-box;
}

.thumbnail.selected {
  border: 3px solid #00f;
  box-sizing: border-box;
}

.thumbnail.selected:hover {
  border: 3px solid #00f;
}

.thumbnail:hover {
  border-color: #888;
}

.thumbnail.selected {
  border: 3px solid #00f;
  box-sizing: border-box;
}

.layer{
  position:absolute;
  width:100%;
  height:100%;
  object-fit:contain;
}

.hidden {
  display: none;
}

.preset-select-wrapper {
  display: inline-block;
  position: relative;
  margin: 10px auto;
}

.preset-toggle-btn {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.preset-list {
  position: absolute;
  top: 110%;
  left: 0;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 9999;
  min-width: 180px;
}

.preset-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.preset-item:hover {
  background-color: #f0f0f0;
}

.preset-item img {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  flex-shrink: 0;
}

.preset-item span {
  font-size: 14px;
  white-space: nowrap;
}

.hidden {
  display: none;
}

.preset-nav {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-top: 1px solid #ddd;
}

.preset-nav button {
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  background: #f5f5f5;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.preset-nav button:hover {
  background: #e0e0e0;
}

.category-tabs{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:6px;
  margin:10px 0;
}

.category-tabs button{
  padding:6px 10px;
  border:1px solid #ccc;
  background:#f5f5f5;
  border-radius:6px;
  cursor:pointer;
}

.category-tabs button.active{
  background:#4da3ff;
  color:white;
}

body,
button,
input,
select{
  font-family: "Zen Maru Gothic", sans-serif;
}

.main-layout{
  display:flex;
  justify-content:center;
  align-items:flex-start;
  gap:40px;
  padding:20px;
}

.left-area{
  width:420px;
  display:flex;
  justify-content:center;
}

.center-area{
  flex:1;
  max-width:700px;
  max-height:90vh;
  overflow-y:auto;
}

.character-area{
  width:200px;
  display:flex;
  flex-direction:column;
  align-items:center;
}

.preset-list{
  max-height:400px;
  overflow-y:auto;
}

#canvas{
  position:relative;
  width:400px;
  height:500px;
  margin:0 auto;

background:white;
  border-radius:20px;

  display:flex;
  justify-content:center;
  align-items:center;

  overflow:hidden;
  box-shadow:
    0 8px 20px rgba(0,0,0,0.15);
}

.right-area{
  flex:1;
  max-width:800px;
  max-height:90vh;
  overflow-y:auto;
  padding-right:10px;
}

#categoryTabs{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-bottom:10px;
}

#partsContainer{
  display:grid;
  grid-template-columns:
    repeat(auto-fill,80px);
  gap:10px;
  margin-top:15px;
}

.thumb-btn{
  width:80px;
  height:80px;
  border-radius:12px;
  border:none;
  background:white;
  box-shadow:
    0 2px 6px rgba(0,0,0,0.1);
}

.bottom-ui{
  position:fixed;
  right:20px;
  bottom:20px;
  background:white;
  padding:10px 14px;
  border-radius:12px;
  box-shadow:
  0 4px 10px rgba(0,0,0,0.15);
}

h1{
  text-align:center;
  margin-bottom:20px;
}

.character-ui{
  position:fixed;
  right:20px;
  top:120px;
  z-index:1000;
}

/* モーダル背景（デフォルトは非表示） */
.modal{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  background: rgba(0,0,0,0.5);

  display: none; /* ← これ重要 */
  justify-content: center;
  align-items: center;

  z-index: 9999;
}

/* hiddenが外れたら表示 */
.modal:not(.hidden){
  display: flex;
}

/* 中身 */
.modal-content{
  background: white;
  padding: 20px;
  border-radius: 16px;
  width: 320px;
  max-width: 90%;

  box-shadow: 0 10px 30px rgba(0,0,0,0.2);

  text-align: left;
}

/* 閉じるボタン */
.modal-content button{
  margin-top: 15px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #4da3ff;
  color: white;
  cursor: pointer;
}

/* =========================
   スマホ用レイアウト
   ========================= */
@media (max-width: 768px) {

.character-ui{
  position:static;
  margin:10px auto;
}

  body{
    padding-bottom:120px;
  }

.main-layout{
  flex-direction:column;
  align-items:center;
  gap:20px;
}
.left-area{
  width:100%;
  justify-content:center;
}
.right-area{
  width:100%;
  max-width:100%;
  max-height:none;
  overflow:visible;
}

#categoryTabs{
  justify-content:center;
}

  /* 保存ボタン */
  .save-button {
    display: block;
    margin: 16px auto 0 auto;
    position: static;
  }

  /* サムネイル6列 */
  .thumbnails{
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    justify-items: center;
    max-width: 100%;
    overflow-x: hidden;
  }

  .thumbnail{
    width: 48px;
    height: 48px;
    margin: 2px;
  }

  /* キャンバス */
  .canvas{
    width: 340px;
    height: 425px;
  }

  .layer{
    width: 340px;
    height: 425px;
  }

}
