/* App screen (web/index.html). Mobile first; must not scroll sideways at 390px. */
:root {
  --bg: #faf7f2; --card: #fff; --ink: #2b2b2b; --muted: #6b6560; --line: #e4ded5;
  --accent: #c94f74; --accent-ink: #fff; --accent-soft: #fbe9ef;
  --ok: #2f7d4f; --warn-bg: #fff6e0; --warn: #8a5a00; --err-bg: #fdecec; --err: #b3261e;
  --fabric: #bdb5a8; --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.6;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  overflow-wrap: anywhere;
}
button, input, output { font: inherit; }

/* header + step display */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top__inner { max-width: 1160px; margin: 0 auto; padding: 12px 16px; }
.title { margin: 0 0 10px; font-size: 1.15rem; }
.title__sub { font-size: .75rem; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; vertical-align: middle; }
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 0; list-style: none; counter-reset: none; }
.steps__item {
  display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 8px; border-radius: 8px;
  background: #f1ece5; color: var(--muted); font-size: .8rem; line-height: 1.3;
}
.steps__num {
  flex: none; display: grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%;
  background: #fff; border: 1px solid var(--line); font-weight: 700;
}
.steps__item.is-done { color: var(--ok); }
.steps__item.is-done .steps__num { background: var(--ok); border-color: var(--ok); color: #fff; }
.steps__item.is-done .steps__num::before { content: "✓"; }
.steps__item.is-done .steps__num { position: relative; color: transparent; }
.steps__item.is-done .steps__num::before { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.steps__item.is-current { background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 2px 6px rgba(201, 79, 116, .35); }
.steps__item.is-current .steps__num { color: var(--accent); border-color: #fff; }
.next { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; margin: 10px 0 0; font-size: .92rem; }
.next__tag { flex: none; font-size: .75rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; }
@media (max-width: 480px) {
  .steps__item { flex-direction: column; text-align: center; padding: 6px 2px; font-size: .72rem; }
}

/* layout */
.layout { max-width: 1160px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.col { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (min-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card__h { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: 1.05rem; }
.card__num { display: grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--accent); color: #fff; font-size: .85rem; }
.card__lead { margin: 0 0 10px; font-size: .9rem; color: var(--muted); }
.sub { margin: 20px 0 8px; font-size: .98rem; }

/* step 1 */
.drop {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 20px 12px; text-align: center;
  border: 2px dashed #d8cfc3; border-radius: var(--radius); background: #fdfbf8; cursor: pointer;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 3px solid rgba(201, 79, 116, .4); outline-offset: 2px; }
.drop__input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.drop__icon { font-size: 1.6rem; line-height: 1; color: var(--accent); }
.drop__main { display: inline-block; margin-top: 4px; padding: 6px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; }
.drop__sub { font-size: .82rem; color: var(--muted); }
.drop__file { font-size: .85rem; font-weight: 700; }
.tips { margin: 10px 0 0; padding-left: 1.2em; font-size: .82rem; color: var(--muted); }

/* step 2 */
.editor { position: relative; width: 100%; max-width: 520px; margin: 0 auto; aspect-ratio: 1; }
.editor__canvas { display: block; width: 100%; height: 100%; border-radius: 8px; touch-action: none; cursor: grab; background: #ece7df; }
.editor__canvas.is-dragging { cursor: grabbing; }
.editor__canvas:focus-visible { outline: 3px solid rgba(201, 79, 116, .5); outline-offset: 2px; }
.editor__empty[hidden] { display: none; }
.editor__empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); font-size: .9rem; pointer-events: none; }
.controls { display: grid; gap: 10px; margin-top: 12px; }
.size { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; font-size: .9rem; }
.size__label { grid-column: 1 / -1; color: var(--muted); }
.size input { width: 100%; min-width: 0; accent-color: var(--accent); }
.size output { font-variant-numeric: tabular-nums; font-size: .85rem; white-space: nowrap; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.warn, .stale { margin: 0; padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: .85rem; }
.stale { margin-top: 10px; }

/* buttons */
.btn {
  appearance: none; border: 1px solid #d3cabd; background: #fff; color: var(--ink); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-size: .9rem; line-height: 1.4;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { display: block; width: 100%; padding: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 700; font-size: 1rem; }
.btn--primary:hover:not(:disabled) { background: #b23f63; color: #fff; }
.btn--icon { width: 2.2em; padding: 6px 0; text-align: center; }

/* error */
.error { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--err-bg); color: var(--err); font-size: .9rem; }
.error p { margin: 0; }
.error__title { font-weight: 700; }
.error__detail { color: var(--ink); }
.error__fix { margin-top: 4px !important; color: var(--ink); }

/* results */
.result { margin-top: 16px; }
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; border-bottom: 2px solid var(--line); }
.tab {
  appearance: none; border: 0; background: none; padding: 8px 2px; margin-bottom: -2px; cursor: pointer;
  border-bottom: 3px solid transparent; color: var(--muted); font-size: .9rem; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.tabnote { margin: 6px 0; font-size: .82rem; color: var(--muted); min-height: 1.3em; }
.zoom { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.zoom__val { min-width: 3.5em; text-align: center; font-variant-numeric: tabular-nums; font-size: .85rem; }
.viewport { width: 100%; aspect-ratio: 1; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #f3efe9; overscroll-behavior: contain; }
.stage { position: relative; width: 100%; aspect-ratio: 1; }
.view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.view[hidden] { display: none; }
.view--px { image-rendering: pixelated; }
.view--svg { background: #fff; }
.view--svg svg { display: block; width: 100%; height: 100%; }
.view--fabric { background: var(--fabric); }
.checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #e6e1da 25%, transparent 25%, transparent 75%, #e6e1da 75%),
    linear-gradient(45deg, #e6e1da 25%, transparent 25%, transparent 75%, #e6e1da 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat { padding: 8px 10px; border-radius: 8px; background: #f7f3ee; min-width: 0; }
.stat--wide { grid-column: span 2; }
.stat dt { font-size: .8rem; color: var(--muted); }
.stat dd { margin: 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat dd.stat__note { font-size: .75rem; font-weight: 400; color: var(--muted); line-height: 1.4; }
.notes { margin: 8px 0 0; padding-left: 1.2em; font-size: .82rem; color: var(--muted); }
.notes:empty { display: none; }
.kinds { margin: 0 0 8px; padding-left: 1.2em; font-size: .82rem; color: var(--muted); }
.parts { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; max-height: 420px; overflow-y: auto; }
.part { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: .85rem; }
.part__swatch { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .25); grid-row: span 2; }
.part__name { font-weight: 700; }
.part__kind { justify-self: end; font-weight: 700; color: var(--accent); white-space: nowrap; }
.part__desc { grid-column: 2 / -1; color: var(--muted); font-size: .78rem; }
.part--skip .part__kind { color: var(--muted); }

.foot { max-width: 1160px; margin: 0 auto; padding: 0 16px 24px; color: var(--muted); }

/* busy overlay */
.busy { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(250, 247, 242, .75); }
.busy[hidden] { display: none; }
.busy__box { display: grid; justify-items: center; gap: 6px; padding: 20px 28px; border-radius: var(--radius); background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .12); font-weight: 700; text-align: center; }
.busy__box small { font-weight: 400; color: var(--muted); }
.busy__spin { width: 32px; height: 32px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .busy__spin { animation: none; } }
