* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: linear-gradient(180deg, #0f1b45 0%, #243a7a 60%, #3f4c8e 100%);
  color: #eaf4ff;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
  gap: 10px;
}

header { text-align: center; }
header h1 { margin: 4px 0 2px; font-size: 22px; }
header p { margin: 0; font-size: 13px; opacity: 0.85; }
header h1 span, header p span { display: inline-block; }

/* 下絵の選択: スマホでも 1 段に 5 個（幅に合わせてサムネイルが縮む） */
#speciesBar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(92vw, 440px);
}
.speciesBtn {
  min-width: 0;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: inherit;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
}
.speciesBtn canvas { width: 100%; height: auto; aspect-ratio: 1; display: block; }
.speciesBtn.selected { border-color: #ffd54f; background: rgba(255, 213, 79, 0.18); }

main { width: 100%; display: flex; justify-content: center; }
#canvasWrap {
  position: relative;
  width: min(92vw, 440px);
  aspect-ratio: 1;
  background: #ffffff;
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
#canvasWrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#line, #text { pointer-events: none; }

#toolbar { width: min(92vw, 440px); display: flex; flex-direction: column; gap: 8px; }
#colors {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.35);
}
.swatch.selected { border-color: #ffd54f; transform: scale(1.12); }

#tools { display: flex; align-items: center; gap: 8px; }
#sizes { display: flex; gap: 6px; }
.sizeBtn {
  width: 44px; height: 44px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
}
.sizeBtn span { display: block; border-radius: 50%; background: #eaf4ff; }
.sizeBtn.selected, #eraser.selected { border-color: #ffd54f; background: rgba(255, 213, 79, 0.18); }

#eraser, #undo, #clear {
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: inherit;
  font-size: 13px;
}

#commentRow { width: min(92vw, 440px); display: flex; flex-direction: column; gap: 8px; }
#commentColors { display: flex; gap: 8px; justify-content: center; }
.swatch.small { width: 30px; height: 30px; border-width: 2px; }
.hint { margin: -2px 0 0; font-size: 12px; opacity: 0.6; text-align: center; }
#comment {
  width: 100%;
  height: 46px;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  color: #eaf4ff;
  font-size: 16px; /* 16px 未満だと iOS がフォーカス時にズームする */
  padding: 0 14px;
  outline: none;
}
#comment:focus { border-color: #ffd54f; }
#comment::placeholder { color: rgba(234,244,255,0.5); }

#send {
  width: min(92vw, 440px);
  height: 58px;
  border: none;
  border-radius: 16px;
  font-size: 19px;
  font-weight: 700;
  color: #072745;
  background: linear-gradient(180deg, #ffe082, #ffb300);
  box-shadow: 0 4px 16px rgba(255, 179, 0, 0.4);
}
#send:disabled { opacity: 0.6; }

/* スクロールを促す下向きの矢印。画面の下に固定、タップは素通り（塗る邪魔をしない） */
#scrollHint {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  margin-left: -22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffe082;
  background: rgba(15, 27, 69, 0.55);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 5;
  opacity: 0.85;
  transition: opacity 0.4s;
  animation: hintBounce 1.6s ease-in-out infinite;
}
#scrollHint.gone { opacity: 0; animation: none; }
@keyframes hintBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}
@media (prefers-reduced-motion: reduce) { #scrollHint { animation: none; } }

#overlay, #confirm, #dialog {
  position: fixed;
  inset: 0;
  background: rgba(4, 20, 38, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
#dialog { z-index: 11; }
#overlay.hidden, #confirm.hidden, #dialog.hidden { display: none; }

/* ページ内のダイアログ（alert / confirm の代わり） */
#dialogMsg { margin: 0 0 18px; font-size: 17px; line-height: 1.6; }

/* 送信前の確認 */
#confirm .big { font-size: 21px; }
#confirmPreview {
  display: block;
  width: min(56vw, 220px);
  aspect-ratio: 1;
  margin: 10px auto 6px;
  background: #fff;
  border-radius: 12px;
  object-fit: contain;
}
#confirm .note { margin: 0 0 14px; font-size: 13px; opacity: 0.75; }
.card .actions { display: flex; gap: 10px; justify-content: center; }
.card .actions button {
  height: 50px;
  padding: 0 22px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
}
#confirmBack, #dialogCancel { border: 2px solid rgba(255,255,255,0.3); background: transparent; color: #eaf4ff; }
#confirmSend, #dialogOk { border: none; color: #072745; background: linear-gradient(180deg, #ffe082, #ffb300); }
.card {
  background: #0b3a66;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  padding: 28px 32px;
  text-align: center;
}
.card .big { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.card p span { display: inline-block; } /* 言葉のまとまりで折り返す */
#again {
  margin-top: 14px;
  height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  color: #072745;
  background: #ffd54f;
}
