* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(#FFF4E0 0%, #FDE7C4 60%, #E9D3A6 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", "Noto Sans JP", sans-serif;
  color: #4A2E16;
  /* スマホ特有の「長押しメニュー」「文字選択」「ダブルタップ拡大」を止める */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

/* ---- 画面の切り替え（mode-home：メニュー／mode-play：遊ぶ） ---- */
.mode-home .hint,
.mode-home #back,
.mode-home #play-hearts,
.mode-play #menu,
.mode-play #days,
.mode-name .hint,
.mode-name #back,
.mode-name #play-hearts,
.mode-name #menu,
.mode-name #days { display: none; }
.name-form { display: none; }
.mode-name .name-form { display: flex; }
.mode-name #tanu-area { width: min(70vw, 36vh * 0.8, 360px); }

/* ---- お試し版 ---- */
.demo-bar { display: none; }
.demo .demo-bar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
}
.demo #back, .demo #play-hearts { display: none; }
.demo-badge {
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
}
.btn-result { font-size: 15px; padding: 9px 16px; }
.btn-result.ready {
  background: #F08A3C;
  color: #fff;
  box-shadow: 0 3px 0 #C8641E;
  animation: nudge 1.6s ease-in-out infinite;
}
@keyframes nudge {
  0%, 70%, 100% { transform: scale(1); }
  80% { transform: scale(1.08); }
  90% { transform: scale(.97); }
}
.res-lead { margin: 0; text-align: center; font-size: 15px; opacity: .7; }
.res-title { margin: 0; text-align: center; font-size: 26px; font-weight: 900; color: #C8641E; }
.res-img { display: block; width: 55%; max-width: 220px; margin: 0 auto; aspect-ratio: 4 / 5; object-fit: contain; }
.res-prev { margin: 0; text-align: center; font-size: 14px; opacity: .75; }
.res-prev.changed { opacity: 1; font-weight: 700; color: #C8641E; }
.res-comment { margin: 0; text-align: center; font-size: 17px; font-weight: 700; }
.btn-main.btn-x { display: block; text-align: center; text-decoration: none; background: #111; box-shadow: 0 4px 0 #444; color: #fff; }
.btn-main.btn-x:active { box-shadow: 0 2px 0 #444; }
.note.center { text-align: center; }
.share-row { display: flex; gap: 8px; }
.btn-follow { display: block; text-align: center; text-decoration: none; font-size: 15px; color: #1D6FD8; }
.share-row .btn { flex: 1; font-size: 14px; padding: 11px 8px; }

/* ---- 呼び名の入力 ---- */
.name-form {
  width: 100%;
  max-width: 360px;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: 16px;
}
.name-input {
  border: 2px solid #E9C89A;
  border-radius: 16px;
  padding: 13px 16px;
  font: inherit;
  font-size: 18px;   /* 16px 未満だと iPhone で画面が拡大されてしまう */
  font-weight: 700;
  text-align: center;
  color: inherit;
  background: #fff;
  -webkit-user-select: text;
  user-select: text;
}
.name-input:focus { outline: none; border-color: #F08A3C; }
.link {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  opacity: .7;
  text-decoration: underline;
  padding: 6px;
  cursor: pointer;
}
.note.small { font-size: 12px; text-align: center; margin: 0; }
.set-row { display: flex; gap: 8px; }
.set-row .name-input { flex: 1; min-width: 0; padding: 10px 12px; }
.sheet-box h3 { margin: 8px 0 0; font-size: 16px; }

/* ---- 上のバー ---- */
#topbar {
  position: relative;
  width: 100%;
  max-width: 460px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.days { text-align: center; line-height: 1.3; }
.days-main { font-size: clamp(18px, 5.4vw, 24px); font-weight: 700; }
.days-main b { font-size: 1.5em; color: #C8641E; margin: 0 2px; }
.days-sub { font-size: 13px; opacity: .65; min-height: 1em; }
.back {
  position: absolute;
  left: 0;
  border: 0;
  background: rgba(255, 255, 255, .7);
  color: inherit;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
#play-hearts { position: absolute; right: 0; }
.hearts { font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
.hearts.pop { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }

/* ---- メニューのボタン ---- */
#menu {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.btn {
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 13px 16px;
  box-shadow: 0 3px 0 rgba(74, 46, 22, .18);
  cursor: pointer;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(74, 46, 22, .18); }
.btn-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #F08A3C;
  color: #fff;
  font-size: 21px;
  padding: 16px;
  box-shadow: 0 4px 0 #C8641E;
}
.btn-main:active { box-shadow: 0 2px 0 #C8641E; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-danger { color: #C0392B; width: 100%; margin-top: 6px; }

/* ---- 実績・設定のパネル ---- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(74, 46, 22, .35);
}
.sheet[hidden] { display: none; }
.sheet-box {
  width: 100%;
  max-width: 400px;
  max-height: 85%;
  overflow: auto;
  background: #FFF9EF;
  border-radius: 22px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet-box h2 { margin: 0; font-size: 20px; text-align: center; }
.rec { width: 100%; border-collapse: collapse; font-size: 15px; }
.rec th, .rec td { padding: 8px 4px; border-bottom: 1px solid rgba(74, 46, 22, .12); }
.rec th { text-align: left; font-weight: 400; }
.rec td { text-align: right; font-weight: 700; white-space: nowrap; }
.note { margin: 4px 0; font-size: 14px; line-height: 1.6; opacity: .8; }

/* ---- お知らせ ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 20;
  transform: translate(-50%, 10px);
  background: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(74, 46, 22, .2);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* メニュー画面ではボタンのぶん、タヌくんを少し小さく */
.mode-home #tanu-area { width: min(80vw, 44vh * 0.8, 400px); }

#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- タヌくん ---- */
#tanu-area {
  position: relative;
  width: min(90vw, 56vh * 0.8, 460px);
  aspect-ratio: 4 / 5;
}
.ground {
  position: absolute;
  left: 12%; right: 12%; bottom: -1%;
  height: 7%;
  border-radius: 50%;
  background: rgba(74, 46, 22, .18);
}
#tanu-move, #tanu-melt, #tanu-body, #tanu-breath {
  position: absolute;
  inset: 0;
  transform-origin: 50% 96%;   /* 足もとを軸にして伸び縮み */
}
#tanu-breath { animation: breath 3.2s ease-in-out infinite; }
@keyframes breath {
  0%, 100% { transform: scale(1, 1); }
  50%      { transform: scale(1.015, .985); }
}
#tanu-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* ---- おなかだけ揺らす重ね絵 ----
   位置と大きさは config.js の bellyJiggle から app.js が --bx などに入れます */
#belly-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transform-origin: var(--bx, 37%) var(--by, 46%);
  -webkit-mask-image: radial-gradient(ellipse var(--brx, 30%) var(--bry, 19%) at var(--bx, 37%) var(--by, 46%), #000 70%, transparent 100%);
          mask-image: radial-gradient(ellipse var(--brx, 30%) var(--bry, 19%) at var(--bx, 37%) var(--by, 46%), #000 70%, transparent 100%);
}
#belly-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  visibility: hidden;
}

/* ---- 「ぽん！」「ぽこ！」の文字 ---- */
.pop-word {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 1px #C8641E;
  text-shadow: 0 2px 0 #C8641E, 0 0 6px rgba(200, 100, 30, .5);
  pointer-events: none;
  white-space: nowrap;
}

#belly-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---- 怒りの絵がないあいだの代用（config.js の angryTint） ---- */
#tanu-img { transition: filter .25s; }
.tint-angry #tanu-img {
  filter: sepia(.3) saturate(1.7) hue-rotate(-18deg);
}
.tint-angry #tanu-breath::after {
  content: "💢";
  position: absolute;
  left: 62%; top: 1%;
  font-size: clamp(30px, 10vw, 48px);
  animation: pop .35s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ---- タップ範囲 ---- */
#zones { position: absolute; inset: 0; }
.zone {
  position: absolute;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.show-zones .zone {
  outline: 2px dashed rgba(229, 50, 45, .7);
  background: rgba(229, 50, 45, .08);
}
.show-zones .zone::after {
  content: attr(data-label);
  position: absolute;
  left: 4px; top: 2px;
  font-size: 12px;
  color: #E5322D;
}

/* ---- ふきだし ---- */
.bubble {
  position: relative;
  white-space: pre-line;   /* セリフの中の改行（\n）をそのまま表示 */
  min-height: 3.2em;
  max-width: min(84vw, 380px);
  margin-bottom: 10px;
  padding: 12px 20px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(74, 46, 22, .15);
  font-size: clamp(17px, 4.8vw, 22px);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(6px) scale(.9);
  transition: opacity .2s, transform .2s;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -10px; left: 50%;
  margin-left: -10px;
  border: 10px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}
.bubble.on {
  opacity: 1;
  transform: none;
  transition: opacity .12s, transform .25s cubic-bezier(.3, 1.6, .5, 1);
}

.hint {
  margin: 22px 0 0;
  font-size: 14px;
  opacity: .55;
}

@media (prefers-reduced-motion: reduce) {
  #tanu-breath { animation: none; }
}
