:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e2e2dd;
  --text: #1c1c1a;
  --text-sub: #77776f;
  --accent: #1c1c1a;
  --guide: #d0342c;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .04em;
}

.main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  align-items: start;
}

/* --- steps --- */
.steps {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.step__heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
}

.step__num {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  letter-spacing: .06em;
}

.step__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step__empty {
  margin: 0;
  font-size: 12px;
  color: var(--text-sub);
}

.step.is-disabled { opacity: .45; pointer-events: none; }

/* --- 選択カード（アイテム / レイアウト共通） --- */
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.card:hover { border-color: #c9c9c2; }

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.card__thumb {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  flex: none;
}

.card__name { font-size: 14px; font-weight: 600; }

.card__sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-sub);
}

/* レイアウトのミニ図。ボックスを % で置くだけ */
.card__mini {
  position: relative;
  width: 44px;
  flex: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.card__mini i {
  position: absolute;
  background: #c9c9c2;
  border-radius: 1px;
}

.card.is-selected .card__mini i { background: var(--accent); }

/* --- toggle --- */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* --- preview --- */
.preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.preview__stage {
  aspect-ratio: 1 / 1;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

.stage__inner { position: relative; width: 100%; height: 100%; }

.preview__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .2s;
}

.preview__image.is-visible { opacity: 1; }

/* 加工範囲。left/top/width/height はアイテム画像に対する % を JS が設定 */
.printarea {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: 1px dashed var(--guide);
  background: rgba(208, 52, 44, .05);
  pointer-events: none;
}

/* display:flex が [hidden] を打ち消すので明示的に消す */
.printarea[hidden] { display: none; }

/*
  ガイドOFF。要素ごと隠すと配置した画像まで消えるので、
  枠線・下地・ラベルだけを落として仕上がりの見た目にする。
*/
.printarea.is-hide-guide {
  outline: none;
  background: none;
}

.printarea.is-hide-guide .printarea__label { display: none; }

.printarea.is-hide-guide .box {
  border-color: transparent;
  background: none;
}

/* ボックスだけクリック可能にする */
.layout { pointer-events: auto; }

.printarea__label {
  position: absolute;
  left: 0;
  bottom: 100%;
  margin-bottom: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--guide);
  color: #fff;
  font-size: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

/*
  レイアウトの座標空間（例 4183x4714）。
  加工範囲へ contain 配置するため、実 px サイズは JS が入れる。
  中のボックスはこの要素に対する % なので、以降の縮尺計算は不要。
*/
.layout { position: relative; }

.box {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #4a7fd0;
  background: rgba(74, 127, 208, .12);
  font: inherit;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow .15s, background .15s;
}

.box:hover { background: rgba(74, 127, 208, .22); }

.box:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.box.is-filled { background: none; border-color: rgba(74, 127, 208, .5); }

.box__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.box__id {
  position: relative;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #2f5da3;
}

.box.is-filled .box__id {
  background: rgba(255, 255, 255, .85);
}

.layout.is-hide-id .box__id { display: none; }

/* --- modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 28, 26, .45);
}

.modal__panel {
  position: relative;
  width: min(720px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal__title { margin: 0; font-size: 16px; font-weight: 600; }

.modal__sub { margin: 4px 0 0; font-size: 12px; color: var(--text-sub); }

.modal__close {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-sub);
}

.modal__close:hover { border-color: #c9c9c2; color: var(--text); }

.modal__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 20px 24px 24px;
  overflow-y: auto;
}

.thumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.thumb:hover { border-color: #c9c9c2; }

.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.thumb.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.thumb__frame {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  background: #f2f2ef;
  border-radius: 4px;
  overflow: hidden;
}

.thumb__frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.thumb__name { font-size: 11px; color: var(--text-sub); text-align: center; }

.thumb--none .thumb__frame { color: var(--text-sub); font-size: 12px; }

/* --- info --- */
.preview__info {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.preview__name { margin: 0; font-size: 18px; font-weight: 600; }

.preview__code,
.preview__color,
.preview__print,
.preview__layout {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-sub);
}

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; padding: 20px; gap: 24px; }
}

/* --- export --- */
.export {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
}

.export:hover { opacity: .85; }

.export:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.export:disabled {
  border-color: var(--border);
  background: var(--border);
  color: var(--text-sub);
  cursor: not-allowed;
}

#exportNote { margin-top: 8px; }
