:root {
  --bg: #0f1419;
  --panel: #171e26;
  --panel-2: #1e2731;
  --line: #2c3845;
  --text: #e8edf2;
  --muted: #9aa8b6;
  --accent: #4fb3ff;
  --accent-ink: #06243a;
  --ok: #4ade80;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- ヘッダー ---------- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #16202b, var(--bg));
  padding: 28px 0 20px;
}
h1 {
  margin: 0;
  font-size: 1.6rem;
}
.tag {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: normal;
}
.lead {
  margin: 6px 0 12px;
  color: var(--muted);
}
.promises {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.promises li {
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(74, 222, 128, 0.12);
  color: var(--ok);
  font-size: 0.85rem;
}
.promises li::before {
  content: "✓ ";
}

/* ---------- ステップ ---------- */
.step {
  margin: 24px 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.step h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1.15rem;
}
.step-no {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: bold;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 32px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone.dragging,
#file-input:focus-visible + .dropzone {
  border-color: var(--accent);
  background: #1b2e40;
}
#file-input:focus-visible + .dropzone {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.dropzone-main {
  font-size: 1.1rem;
  font-weight: bold;
}
.dropzone-sub,
.dropzone-limits {
  color: var(--muted);
  font-size: 0.9rem;
}
.pointer-coarse {
  display: none;
}
/* マウスが無いタッチ操作の画面（スマホ・タブレット） */
@media (hover: none) and (pointer: coarse) {
  .pointer-fine {
    display: none;
  }
  .pointer-coarse {
    display: inline;
  }
}
.fake-button {
  display: inline-block;
  margin-left: 4px;
  padding: 4px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: bold;
}

/* 読み込み中は枠を押せないことが分かるようにする */
.dropzone.busy {
  opacity: 0.55;
  cursor: progress;
  pointer-events: none;
}

/* ---------- ステップ1の読み込み状況 ---------- */
.load-status {
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.load-status p {
  margin: 0;
}
.load-status.is-loading {
  border-color: var(--accent);
}
.load-status.is-done {
  border-color: rgba(74, 222, 128, 0.5);
}
.load-main {
  font-weight: bold;
}
.is-done .load-main {
  color: var(--ok);
}
.is-done .load-main.load-none {
  color: var(--text);
}
.load-sub {
  color: var(--muted);
  font-size: 0.9rem;
}
.load-sub a {
  color: var(--accent);
}
.load-warn {
  color: var(--warn);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

/* ---------- 選択肢 ---------- */
.group {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}
.group:last-child {
  margin-bottom: 0;
}
legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: bold;
}
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.choice {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 12px 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
}
.choice input {
  position: absolute;
  top: 16px;
  left: 14px;
  accent-color: var(--accent);
}
.choice:has(input:checked) {
  border-color: var(--accent);
  background: #1b2e40;
}
.choice-title {
  font-weight: bold;
}
.choice-desc {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}
.badge-provisional {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
  font-size: 0.75rem;
  font-weight: normal;
}

.custom-size {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
}
.custom-size[hidden] {
  display: none;
}
input[type="number"] {
  width: 6.5em;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  cursor: pointer;
}
.chip:has(input:checked) {
  border-color: var(--accent);
}
.chip.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.chip input[type="radio"] {
  accent-color: var(--accent);
}
input[type="color"] {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: none;
}

.quality-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 12px;
}
.quality-row[hidden] {
  display: none;
}
.quality-row input[type="range"] {
  flex: 1 1 180px;
  accent-color: var(--accent);
}
output {
  display: inline-block;
  min-width: 2em;
  font-weight: bold;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.message {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--warn);
}
.message:empty {
  display: none;
}
.message.error {
  color: var(--error);
}

/* ---------- 結果 ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.summary {
  margin: 0;
  color: var(--muted);
}
.results {
  display: grid;
  gap: 14px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.result {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.result-rejected,
.result-failed {
  border-color: rgba(248, 113, 113, 0.6);
}
.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}
.result-name {
  min-width: 0;
  font-weight: bold;
  overflow-wrap: anywhere;
}
.status {
  font-size: 0.85rem;
  color: var(--muted);
}
.status-done {
  color: var(--ok);
}
.status-rejected,
.status-failed {
  color: var(--error);
}
.result-error {
  margin: 6px 0 0;
  color: var(--error);
  font-size: 0.9rem;
}
.result-warning {
  margin: 8px 0 0;
  color: var(--warn);
  font-size: 0.85rem;
}

.preview-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.preview {
  margin: 0;
  min-width: 0;
}
.preview-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 180px;
  border-radius: 8px;
  /* 透明部分が分かるよう市松模様を敷く */
  background-color: #2a3440;
  background-image: linear-gradient(45deg, #333f4c 25%, transparent 25%), linear-gradient(-45deg, #333f4c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333f4c 75%), linear-gradient(-45deg, transparent 75%, #333f4c 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  overflow: hidden;
}
.preview-frame img {
  /* 枠いっぱいに置き、縦横比を保ったまま全体を表示する（切り抜かない） */
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.preview-placeholder {
  color: var(--muted);
  font-size: 0.85rem;
}
.preview figcaption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 10px;
}
.file-name {
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

/* ---------- ボタン ---------- */
.button {
  display: inline-block;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
}
.button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.button.secondary {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
}
.button.small {
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: normal;
}
.button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.button:focus-visible,
.choice:has(input:focus-visible),
.chip:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 説明 ---------- */
.notes {
  margin: 24px 0 40px;
  color: var(--muted);
  font-size: 0.9rem;
}
.notes h2 {
  font-size: 1rem;
  color: var(--text);
}
.notes ul {
  padding-left: 1.2em;
}

/* ---------- 保存先の説明 ---------- */
.save-help {
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.save-help summary {
  color: var(--text);
  cursor: pointer;
}
.save-help ul {
  margin: 8px 0;
  padding-left: 1.2em;
}
.save-help p {
  margin: 0;
}

/* ---------- タッチ操作の画面（スマホ・タブレット）：押しやすい大きさにする ---------- */
@media (hover: none) and (pointer: coarse) {
  .button,
  .chip {
    min-height: 44px;
  }
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .button.small {
    padding: 8px 16px;
    font-size: 0.9rem;
  }
  .result-actions {
    gap: 12px 16px;
  }
  input[type="color"] {
    width: 44px;
    height: 32px;
  }
  input[type="number"] {
    min-height: 44px;
    font-size: 16px; /* 16px 未満だと iPhone が入力時に画面を拡大してしまう */
  }
  input[type="range"] {
    min-height: 44px;
  }
  .save-help summary {
    padding: 11px 0;
  }
  .load-sub a {
    display: inline-block;
    padding: 12px 0;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 1.3rem;
  }
  .step {
    padding: 16px;
  }
  .preview-frame {
    height: 130px;
  }
}
