:root {
  --bg: #0f0f12;
  --bg-2: #16161b;
  --bg-3: #1d1d24;
  --line: #2a2a33;
  --text: #e7e7ea;
  --text-dim: #9a9aa3;
  --accent: #e23b3b;
  --accent-soft: #f25555;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", system-ui, sans-serif;
  font-size: 14px;
  user-select: none;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}

.label {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

/* ---- 上部バー ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.name-input {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  width: 180px;
  outline: none;
}
.name-input:focus { border-color: var(--text-dim); }

/* ---- 第2バー ---- */
.actionbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 14px;
  border-bottom: 1px dashed var(--line);
}
.fill-group { display: flex; align-items: center; gap: 10px; }

.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 4px 0 0;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
}
.swatch input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 50px;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.swatch .caret { color: var(--text-dim); font-size: 20px; }

.divider { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--accent-soft);
  cursor: pointer;
  transition: background .12s;
}
.icon-btn:hover { background: var(--bg-3); }
.icon-btn:active { background: var(--bg-2); }
.icon-btn:disabled { color: #44444a; cursor: default; background: transparent; }
.icon-btn.toggle.active { background: var(--accent); color: #fff; }
.icon-btn.toggle.active:hover { background: var(--accent-soft); }

/* ---- メイン ---- */
.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 左ツール */
.tools {
  display: grid;
  grid-template-columns: repeat(2, 48px);
  grid-auto-rows: 48px;
  gap: 8px;
  padding: 12px;
  align-content: start;
}
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.tool-btn:hover { background: var(--bg-3); }
.tool-btn.active { background: var(--accent); color: #fff; }

/* 中央キャンバス */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 20px;
}
#editor-canvas {
  background: #000;
  image-rendering: pixelated;
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.costume-strip {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  min-height: 64px;
  align-items: center;
}
.costume-thumb {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background:
    conic-gradient(#3a3a3a 25%, #2a2a2a 0 50%, #3a3a3a 0 75%, #2a2a2a 0) 0 0 / 12px 12px;
  cursor: pointer;
  flex: 0 0 auto;
  overflow: hidden;
}
.costume-thumb canvas { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; }
.costume-thumb.active { border-color: var(--accent); }
.costume-thumb .badge {
  position: absolute;
  bottom: 1px;
  right: 1px;
  font-size: 12px;
  color: #fff;
  background: rgba(0,0,0,.55);
  border-radius: 4px;
  padding: 0 1px;
}
.costume-thumb .badge .material-symbols-outlined { font-size: 13px; }

/* 右プレビュー */
.preview-panel {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
}
.mode-toggle {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}
.mode-toggle button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 7px;
  padding: 8px 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
}
.mode-toggle button .material-symbols-outlined { font-size: 18px; }
.mode-toggle button.active { background: var(--accent); color: #fff; }

.preview-canvas-wrap {
  flex: 1;
  min-height: 0;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 40%, #1c1c24, #0c0c10);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}
.preview-canvas-wrap canvas { display: block; }
.preview-hint {
  margin: 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  min-height: 16px;
}
