:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #e3e5ea;
  --color-text: #1f2330;
  --color-text-sub: #5b6275;
  --color-primary: #2856ff;
  --color-primary-hover: #1d44d6;
  --color-primary-fg: #ffffff;
  --color-error-bg: #ffe9e9;
  --color-error-fg: #b3261e;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(20, 24, 32, 0.04), 0 4px 18px rgba(20, 24, 32, 0.06);
  --shadow-focus: 0 0 0 3px rgba(40, 86, 255, 0.25);
  --header-h: 64px;
  --content-max: 1200px;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
  line-height: 1.6;
}

img { max-width: 100%; display: block; }

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* --- Header --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: env(safe-area-inset-top) 16px 0;
}
.app-header-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 12px 0;
}
.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.app-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--color-text-sub);
}

/* --- Layout --- */
.page-wrapper {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.main-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 960px) {
  .main-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
  }
  .right-panel {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    align-self: start;
  }
}

/* --- Card --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 16px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 14px;
}
.section-title .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-size: 13px;
  font-weight: 700;
}
.section-hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--color-text-sub);
  font-weight: 500;
}

/* --- モード切替タブ (PITD-998: コーディネート / モデル着用) --- */
.mode-tabs {
  display: flex;
  gap: 8px;
}
.mode-tab { position: relative; display: flex; flex: 1 1 0; }
.mode-tab input { position: absolute; opacity: 0; pointer-events: none; }
.mode-tab span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-sub);
  background: var(--color-surface);
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.mode-tab input:checked + span {
  border-color: var(--color-primary);
  background: rgba(40, 86, 255, 0.08);
  color: var(--color-primary);
}
.mode-tab input:focus-visible + span { box-shadow: var(--shadow-focus); }

/* --- Layout option --- */
.layout-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 480px) {
  .layout-options { grid-template-columns: 1fr; }
}
.layout-option { display: block; cursor: pointer; }
.layout-option input { position: absolute; opacity: 0; pointer-events: none; }
.layout-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  text-align: center;
  transition: border-color .15s ease, background .15s ease,
    box-shadow .15s ease, transform .05s ease;
}
.layout-option:hover .layout-card {
  border-color: #b6c2e6;
  background: #fafbff;
}
.layout-option input:checked + .layout-card {
  border-color: var(--color-primary);
  background: rgba(40, 86, 255, 0.08);
  box-shadow: 0 4px 12px rgba(40, 86, 255, 0.14);
}
.layout-option input:focus-visible + .layout-card { box-shadow: var(--shadow-focus); }

/* 選択中であることを示すチェックマーク (右上バッジ)。
   サムネイル画像より手前に出すため z-index で前面に固定し、
   背景画像と重なっても視認できるよう白フチを付ける。 */
.layout-card-check {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-size: 13px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity .15s ease, transform .15s ease;
}
.layout-option input:checked + .layout-card .layout-card-check {
  opacity: 1;
  transform: scale(1);
}

.layout-card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 160px;
  border-radius: 8px;
  background-color: #f1f3f7;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  display: block;
  position: relative;
  overflow: hidden;
}
/* 各レイアウトの実例画像 (static/images/layoutN.png) を背景として表示 */
.layout-thumb-layout1 { background-image: url("../images/layout1.png"); }
.layout-thumb-layout2 { background-image: url("../images/layout2.png"); }
.layout-thumb-layout3 { background-image: url("../images/layout3.png"); }
.layout-card-label {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text);
}
.layout-option input:checked + .layout-card .layout-card-label {
  color: var(--color-primary);
}

/* --- モデル選択 (PITD-998: HANA/KEN、イメージ画像付きボタン) --- */
.model-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.model-option { display: block; cursor: pointer; }
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  text-align: center;
  transition: border-color .15s ease, background .15s ease,
    box-shadow .15s ease, transform .05s ease;
}
.model-option:hover .model-card {
  border-color: #b6c2e6;
  background: #fafbff;
}
.model-option input:checked + .model-card {
  border-color: var(--color-primary);
  background: rgba(40, 86, 255, 0.08);
  box-shadow: 0 4px 12px rgba(40, 86, 255, 0.14);
}
.model-option input:focus-visible + .model-card { box-shadow: var(--shadow-focus); }
.model-card-check {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-size: 13px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity .15s ease, transform .15s ease;
}
.model-option input:checked + .model-card .model-card-check {
  opacity: 1;
  transform: scale(1);
}
.model-card-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  max-width: 160px;
  border-radius: 8px;
  background-color: #f1f3f7;
  object-fit: cover;
  display: block;
}
.model-card-label {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text);
}
.model-option input:checked + .model-card .model-card-label {
  color: var(--color-primary);
}

/* --- Upload --- */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: #fafbfd;
  transition: border-color .15s ease, background .15s ease;
}
.upload-area:hover, .upload-area.is-drag {
  border-color: var(--color-primary);
  background: rgba(40, 86, 255, 0.04);
}
.upload-icon {
  font-size: 30px;
  font-weight: 300;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: 8px;
}
.upload-main-text { font-weight: 600; font-size: 15px; }
.upload-sub-text { font-size: 12px; color: var(--color-text-sub); margin-top: 2px; }

.thumb-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.thumb-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: #f1f3f7;
}
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 24, 32, 0.7);
  color: #fff;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  padding: 0;
}
.upload-counter {
  margin-top: 8px;
  font-size: 12px;
  color: var(--color-text-sub);
  text-align: right;
}

/* --- Color picker --- */
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}
.color-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  position: relative;
  padding: 4px 0;
}
.color-swatch input { position: absolute; opacity: 0; pointer-events: none; }
.color-chip {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 56px;
  border-radius: 50%;
  background: var(--swatch-color);
  border: 1px solid rgba(20, 24, 32, 0.12);
  box-shadow: inset 0 0 0 0 var(--color-primary);
  transition: box-shadow .15s ease, transform .15s ease;
}
.color-swatch input:checked + .color-chip {
  box-shadow:
    inset 0 0 0 3px #fff,
    0 0 0 3px var(--color-primary);
  transform: scale(1.05);
}
.color-swatch input:focus-visible + .color-chip {
  box-shadow:
    inset 0 0 0 3px #fff,
    0 0 0 3px var(--color-primary);
}
.color-name {
  font-size: 11px;
  color: var(--color-text-sub);
  text-align: center;
  line-height: 1.2;
}

/* --- Form --- */
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.form-label { font-size: 14px; font-weight: 600; }
.form-select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--color-surface);
  min-width: 120px;
}
.form-select:focus { outline: none; box-shadow: var(--shadow-focus); border-color: var(--color-primary); }

/* --- ディスクレーマー切替 (ラジオ) --- */
.radio-inline {
  display: inline-flex;
  gap: 8px;
}
.radio-pill { position: relative; display: inline-flex; }
.radio-pill input { position: absolute; opacity: 0; pointer-events: none; }
.radio-pill span {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-sub);
  background: var(--color-surface);
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.radio-pill input:checked + span {
  border-color: var(--color-primary);
  background: rgba(40, 86, 255, 0.08);
  color: var(--color-primary);
}
.radio-pill input:focus-visible + span { box-shadow: var(--shadow-focus); }

.disclaimer-note {
  margin: 0 0 12px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--color-text-sub);
}
.disclaimer-note-text {
  display: inline-block;
  margin-top: 4px;
  color: var(--color-text);
  font-weight: 500;
}

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  border: none;
  text-decoration: none;
  transition: background .15s ease, transform .05s ease;
  min-height: 48px;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-fg);
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: #f1f3f7;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: #e7eaef; }

.hint-text {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--color-text-sub);
  text-align: center;
}

/* --- Result panel --- */
.result-card { min-height: 260px; }
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 16px;
  color: var(--color-text-sub);
  text-align: center;
}
.placeholder-icon { font-size: 40px; line-height: 1; }
.loading-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 16px;
}
.loading-text { color: var(--color-text-sub); margin: 0; }
.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid #dde1ea;
  border-top-color: var(--color-primary);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-area {
  background: var(--color-error-bg);
  color: var(--color-error-fg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.error-text { margin: 0; font-size: 14px; line-height: 1.5; }

.result-image-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.result-image-area img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: #f1f3f7;
}

/* --- 修正リクエストエリア --- */
.edit-area {
  margin-top: 16px;
  padding: 16px;
  background: #f7f8fb;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}
.edit-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}
.edit-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--color-text-sub);
  line-height: 1.5;
}
.form-textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--color-surface);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 80px;
}
.form-textarea:focus {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-color: var(--color-primary);
}
.edit-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}
.btn-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s ease, transform .05s ease;
}
.btn-edit:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-edit:active:not(:disabled) { transform: translateY(1px); }
.btn-edit:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-edit-icon {
  font-size: 15px;
  line-height: 1;
  display: inline-block;
}

/* --- Footer --- */
.app-footer {
  text-align: center;
  color: var(--color-text-sub);
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* --- Mobile fine-tuning --- */
@media (max-width: 480px) {
  .app-title { font-size: 16px; }
  .app-subtitle { font-size: 11px; }
  .section-title { font-size: 15px; }
  .card { padding: 14px; }
  .btn-primary, .btn-secondary { font-size: 15px; padding: 13px 16px; }
}

/* --- Touch feedback --- */
@media (hover: none) {
  .layout-option:active .layout-card { background: rgba(40, 86, 255, 0.06); }
  .color-swatch:active .color-chip { transform: scale(0.96); }
}
