:root {
  --bg: #f6f5fa; --card: #fff; --ink: #2f2d42; --sub: #6f6c86; --line: #e4e2ee;
  --accent: #6c5ce7; --accent-d: #5446c9; --danger: #c0392b;
}
* { box-sizing: border-box; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }   /* 더블탭 확대 방지 */
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
.wrap {
  max-width: 760px; margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-right)) calc(56px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.lead { margin: 0 0 16px; color: var(--sub); font-size: 14px; }

/* 게임 화면 */
.stage {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px; box-shadow: 0 1px 2px rgba(40, 30, 90, .04);
}
canvas#game {
  display: block; width: 100%; height: auto; border-radius: 10px; background: #fff;
  touch-action: none;                                   /* 게임 화면 위에서는 스크롤·확대 대신 점프 */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  outline: none; cursor: pointer;
}
.hint { margin: 8px 4px 2px; font-size: 12.5px; color: var(--sub); text-align: center; }
.hint-touch { display: none; }
@media (pointer: coarse) { .hint-kb { display: none; } .hint-touch { display: inline; } }

/* 설정 패널 */
.panel {
  margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 16px; box-shadow: 0 1px 2px rgba(40, 30, 90, .04);
}
.row { padding: 14px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.label { font-size: 13px; font-weight: 700; margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.label small { font-weight: 400; color: var(--sub); font-size: 12px; }

input[type=text], select {
  font: inherit; font-size: 16px;                       /* 16px 미만이면 iOS가 입력할 때 화면을 확대함 */
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input[type=text] { width: 100%; }
select { max-width: 100%; }
input[type=text]:focus, select:focus { outline: 2px solid #cfc8ff; border-color: var(--accent); }
input[type=file] { display: none; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; padding: 9px 14px; min-height: 40px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; line-height: 1.2;
}
.btn:hover { background: #f3f1fb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { font-size: 13px; padding: 6px 12px; min-height: 36px; font-weight: 500; }
[hidden] { display: none !important; }

.files { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.thumbs canvas, .slot canvas {
  width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 8px;
  background: repeating-conic-gradient(#f0eef7 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}
.slot canvas.fallback { opacity: .45; }

/* 캐릭터 이미지 슬롯(달리기 / 점프 / 사망) */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.slot { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.slot canvas { width: 56px; height: 56px; }
.slot b { font-size: 13px; }
.slot small { color: var(--sub); font-size: 11.5px; line-height: 1.3; min-height: 15px; }
.slot .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

/* 배경 선택 */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw {
  appearance: none; border: 2px solid transparent; background: none; padding: 3px; border-radius: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font: inherit; font-size: 12px; color: var(--sub);
}
.sw canvas { width: 80px; height: 43px; border-radius: 7px; border: 1px solid var(--line); display: block; }
.sw[aria-pressed=true] { border-color: var(--accent); color: var(--ink); font-weight: 700; }

.opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 14px; }
.opts label { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 40px; }
.opts input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.note { margin-top: 6px; font-size: 12.5px; color: var(--sub); }
.exp { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.exp .btn.primary { min-height: 46px; padding: 10px 20px; font-size: 15px; }

.msg { font-size: 13px; color: var(--sub); min-height: 20px; margin-top: 8px; }
.msg.err { color: var(--danger); }
.preview { margin-top: 10px; display: none; }
.preview.on { display: block; }
.preview img {
  display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px;
  background: repeating-conic-gradient(#f0eef7 0 25%, #fff 0 50%) 0 0 / 12px 12px;
  -webkit-touch-callout: default;                      /* 길게 눌러 저장할 수 있게 */
}
.preview p { margin: 6px 2px 8px; font-size: 12.5px; color: var(--sub); }
.foot { margin-top: 18px; font-size: 12px; color: var(--sub); text-align: center; }

/* 모바일 */
@media (max-width: 560px) {
  .wrap { padding-top: 16px; }
  h1 { font-size: 20px; }
  .stage { padding: 6px; border-radius: 14px; }
  .panel { padding: 2px 12px; }
  .slots { grid-template-columns: 1fr; }
  .slot { flex-direction: row; text-align: left; gap: 12px; }
  .slot .meta { flex: 1; display: flex; flex-direction: column; gap: 2px; }
  .swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .sw canvas { width: 100%; height: auto; aspect-ratio: 420 / 224; }
  #scaling { flex: 1; min-width: 0; }
}
@media (min-width: 561px) { .slot .meta { display: contents; } }
