* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1c3550;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #eaf4fb;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ===== 上の表示 ===== */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 6px;
  border-radius: 99px;
  background: rgba(20, 45, 80, .6);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25);
}
.chip img { width: 32px; height: 32px; object-fit: contain; }
.chip .ico { font-size: 22px; margin-left: 4px; }
.chip small { font-size: 11px; font-weight: 700; opacity: .9; }
.money { min-width: 96px; }
.hud .chip.rescued { flex: 0 1 auto; }
.hud-btn.map { margin-left: auto; }
.hud-btn {
  margin-left: 0;
  width: 44px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  font-size: 20px;
  background: linear-gradient(#5b9bff, #2466d8);
  box-shadow: 0 4px 0 #173a7a;
  pointer-events: auto;
  cursor: pointer;
}

/* ===== 次にやること ===== */
.guide {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 4px 16px 4px 4px;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(30, 64, 110, .94), rgba(16, 38, 70, .94));
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 6px 14px rgba(0, 25, 60, .35);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .02em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  pointer-events: none;
}
.guide.pop { animation: guideIn .35s cubic-bezier(.2, 1.6, .4, 1); }
.guide .g-ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #ffc24a 60%, #f39a1e);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .15), 0 0 0 2px #fff;
}
.guide .g-ico img { width: 28px; height: 28px; object-fit: contain; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3)); }
.guide .g-txt { overflow: hidden; text-overflow: ellipsis; }
.guide.hidden { display: none; }
@keyframes guideIn { from { transform: translate(-50%, -6px) scale(.85); opacity: 0; } }

/* ===== スタート画面 ===== */
.start {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, .2), transparent 60%),
    linear-gradient(rgba(30, 70, 120, .75), rgba(20, 45, 80, .9));
  color: #fff;
  text-align: center;
  cursor: pointer;
}
.start.hidden { display: none; }
.logo {
  margin: 0;
  font-size: 60px;
  line-height: 1;
  font-weight: 900;
  color: #fff;
  letter-spacing: .04em;
  transform: rotate(-4deg);
  text-shadow: 0 3px 0 #7fb8e6, 0 6px 0 #4d8bb8, 0 9px 0 #2d5f8a, 0 14px 20px rgba(0, 0, 0, .5);
  animation: logoDrop .9s cubic-bezier(.3, 1.6, .5, 1) both;
}
@keyframes logoDrop { from { transform: translateY(-120%) rotate(-4deg) scale(1.5); opacity: 0; } }
.start-story { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.6; }   /* 会話の .story と名前を分ける（同じ名前だと全面に広がって画面が暗くなる） */
.howto { margin: 0; font-size: 13px; opacity: .85; line-height: 1.6; }
/* AIゲーム実験室のトップ（ほかのゲーム一覧）へ戻るリンク */
.start-games {
  padding: 6px 14px;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.start-games:active { transform: translateY(2px); }
/* リンクの前のアイコン（絵文字は使わない） */
.lk-ic { width: 24px; height: 24px; margin: -5px 4px -5px -2px; vertical-align: middle; }
.big-btn {
  font-size: 22px;
  font-weight: 900;
  padding: 14px 28px;
  color: #fff;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(#ffb347, #ff7a18);
  box-shadow: 0 6px 0 #a34700, 0 10px 16px rgba(0, 0, 0, .3);
  animation: pulse 1.4s ease-in-out infinite;
  cursor: pointer;
}
@keyframes pulse { 50% { transform: scale(1.06); } }

/* 所持金・救った人数が増えたとき、ぴょんと跳ねる */
.chip.bump { animation: chipBump .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes chipBump { 40% { transform: scale(1.18); background: rgba(255, 190, 40, .75); } }

/* スタート画面の絵 */
.start-art { position: relative; width: 280px; height: 170px; margin-bottom: -10px; }
.start-art img { position: absolute; bottom: 0; filter: drop-shadow(0 10px 10px rgba(0, 0, 0, .45)); }
.art-bear { right: 0; width: 160px; animation: artBear 2.4s ease-in-out infinite; }
.art-hero { left: 20px; width: 130px; animation: artHero 1.2s ease-in-out infinite; }
.art-meat { left: 120px; bottom: 110px; width: 56px; animation: artMeat 1.6s ease-in-out infinite; }
@keyframes artBear { 50% { transform: translateY(-6px) rotate(2deg); } }
@keyframes artHero { 50% { transform: translateY(-10px) rotate(-4deg); } }
@keyframes artMeat { 50% { transform: translateY(-12px) rotate(18deg); } }
/* 背の低い画面（iPhone SE など）では絵とロゴを少し小さくして、下のリンクまで1画面に収める */
@media (max-height: 640px) {
  .start { gap: 8px; padding: 12px 16px; }
  .start .logo { font-size: 48px; }
  .start-art { height: 130px; transform: scale(.78); transform-origin: 50% 100%; margin: 0 0 -6px; }
}

/* ===== 強化ボタン（右下） ===== */
.up-btn {
  position: absolute;
  right: 14px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 74px;
  height: 74px;
  border: 0;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(#ffb347, #ff7a18);
  box-shadow: 0 5px 0 #a34700, 0 8px 14px rgba(0, 0, 0, .3);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  cursor: pointer;
}
.up-btn span { font-size: 24px; line-height: 1; }
.up-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #a34700; }
/* 強化できるものがあると「！」が付いて弾む */
.up-btn.ready { animation: upReady 1s ease-in-out infinite; }
.up-btn.ready::after {
  content: '!';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e8342b;
  box-shadow: 0 0 0 3px #fff;
  font-size: 16px;
  line-height: 24px;
}
@keyframes upReady { 50% { transform: scale(1.08); } }

/* ===== 強化画面 ===== */
.upgrades {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(10, 25, 45, .55);
}
.upgrades.hidden { display: none; }
.up-panel {
  width: 100%;
  max-height: 78%;
  display: flex;
  flex-direction: column;
  border-radius: 22px 22px 0 0;
  background: linear-gradient(#f4f9fd, #dcebf7);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .3);
  animation: sheetUp .28s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.up-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.up-head h2 { margin: 0; font-size: 22px; color: #1d3a5f; }
.up-head .chip { margin-left: auto; height: 36px; font-size: 18px; min-width: 0; }
.up-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #9fb3cc;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}
.up-list { overflow-y: auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.up-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(30, 60, 100, .12);
}
.up-row > img { width: 48px; height: 48px; object-fit: contain; }
.up-info { flex: 1; min-width: 0; }
.up-name { font-size: 15px; font-weight: 900; color: #1d3a5f; }
.up-name span { margin-left: 6px; font-size: 11px; color: #2466d8; }
.up-val { font-size: 13px; color: #556; }
.up-val b { color: #1f9d3a; }
.up-buy {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 84px;
  justify-content: center;
  padding: 10px 8px;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(#4fd46a, #1f9d3a);
  box-shadow: 0 4px 0 #0f5e21;
  cursor: pointer;
}
.up-buy img { width: 22px; }
.up-buy:disabled { filter: grayscale(1); opacity: .55; cursor: default; }
.up-buy:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #0f5e21; }

/* ===== 村の目標（救った人数のゲージ） ===== */
.goal {
  position: absolute;
  top: 56px;
  left: 12px;
  right: 12px;
  padding: 4px 10px 6px;
  border-radius: 12px;
  background: rgba(20, 45, 80, .55);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
}
.goal-top { display: flex; justify-content: space-between; margin-bottom: 3px; text-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
.goal-track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .25); overflow: hidden; }
.goal-bar { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, #7fe0ff, #4fd46a); transition: width .4s; }
.goal.done .goal-bar { background: linear-gradient(90deg, #ffd23f, #ff9a3b); }
.guide { top: 104px; }

/* ===== 全体マップ ===== */
.map {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .6), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(180, 215, 245, .7), transparent 45%),
    linear-gradient(#cfe6f7, #eef6fc);
}
.map.hidden { display: none; }
.map-head { display: flex; align-items: center; padding: 14px 16px 6px; }
.map-head h2 { margin: 0; font-size: 22px; color: #1d3a5f; }
.map-head .up-close { margin-left: auto; }
.map-area { position: relative; flex: 1; margin: 6px 18px; }
.map-tabs { display: flex; gap: 8px; padding: 2px 16px 4px; }
.map-tab { flex: 1; padding: 7px 0; border: 0; border-radius: 12px; background: rgba(29, 58, 95, .12); color: #1d3a5f; font-family: inherit; font-size: 14px; font-weight: 900; cursor: pointer; }
.map-tab.on { background: #1d3a5f; color: #fff; }
.map-tab:disabled { opacity: .5; cursor: default; }
.map-path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.map-path .road { fill: none; stroke: rgba(120, 140, 170, .45); stroke-width: 1.6; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; stroke-width: 6; }
.map-path .road.open { stroke: #e3a13a; stroke-dasharray: none; stroke-width: 7; }
.map-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 130px;
  transform: translate(-50%, -60%);
  border: 0;
  background: none;
  cursor: pointer;
}
.map-node img {
  width: 76px;
  height: 76px;
  object-fit: contain;
  padding: 6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px #7fb8e6, 0 6px 12px rgba(0, 0, 0, .25);
}
.map-node.done img { box-shadow: 0 0 0 4px #ffd23f, 0 6px 12px rgba(0, 0, 0, .25); }
.map-node.current img { animation: nodePulse 1.2s ease-in-out infinite; }
@keyframes nodePulse { 50% { transform: scale(1.1); box-shadow: 0 0 0 6px #ff9a3b, 0 0 20px #ffd23f; } }
.map-node.locked { cursor: default; }
.map-node.locked img { filter: grayscale(1) brightness(.8); opacity: .7; }
.map-name { margin-top: 6px; padding: 2px 8px; border-radius: 8px; background: rgba(29, 58, 95, .85); color: #fff; font-size: 12px; font-weight: 900; white-space: nowrap; }
.map-state { margin-top: 2px; font-size: 12px; font-weight: 900; color: #1d3a5f; }
.map-node.done .map-state { color: #c07a00; }
.map-note { margin: 0 0 8px; text-align: center; font-size: 13px; font-weight: 700; color: #3a5a80; }
/* 感想ページへのリンク（同じタブで開く。離れる前にセーブする） */
.map-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 12px calc(14px + env(safe-area-inset-bottom));
}
.map-feedback {
  align-self: center;
  padding: 6px 16px;
  border-radius: 99px;
  background: rgba(29, 58, 95, .85);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}
.map-feedback:active { transform: translateY(2px); }

/* ===== 会話 ===== */
.story {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  padding: 16px 12px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent 35%, rgba(10, 25, 45, .75));
  cursor: pointer;
}
.story.hidden { display: none; }
.story-face {
  position: absolute;
  left: 8px;
  bottom: 170px;
  width: 150px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .4));
  animation: faceIn .3s ease-out;
}
.story-face.hidden { display: none; }
@keyframes faceIn { from { transform: translateX(-30px); opacity: 0; } }
.story-box {
  position: relative;
  width: 100%;
  min-height: 130px;
  padding: 26px 16px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 0 0 3px #7fb8e6, 0 8px 20px rgba(0, 0, 0, .3);
  color: #1d3a5f;
}
.story-box.narr { background: rgba(20, 40, 70, .92); color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .4); text-align: center; }
.story-name {
  position: absolute;
  top: -14px;
  left: 14px;
  padding: 4px 14px;
  border-radius: 99px;
  background: linear-gradient(#ffb347, #ff7a18);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
}
.story-name.hidden { display: none; }
.story-text { font-size: 17px; font-weight: 700; line-height: 1.6; min-height: 54px; }
.story-next { margin-top: 6px; text-align: right; font-size: 12px; opacity: .6; animation: nextBlink 1s steps(2) infinite; }
@keyframes nextBlink { 50% { opacity: .2; } }

/* ===== 志願者の選択 ===== */
.recruit {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  padding: 16px 12px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent 30%, rgba(10, 25, 45, .75));
}
.recruit.hidden { display: none; }
.recruit .story-face { bottom: 250px; }
.recruit-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.recruit-choices button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(#fff4d6, #ffd98a);
  box-shadow: 0 3px 0 #d9a13b;
  color: #5a3a00;
  font: 900 16px/1.2 inherit;
  text-align: left;
  cursor: pointer;
}
.recruit-choices button img { width: 36px; height: 36px; object-fit: contain; }
.recruit-choices button small { display: block; font-size: 11px; font-weight: 700; opacity: .7; }
.recruit-choices button:disabled { filter: grayscale(1); opacity: .5; }
.recruit-choices button.later { background: rgba(0, 0, 0, .06); box-shadow: none; color: #1d3a5f; justify-content: center; font-size: 13px; }
.recruit-choices button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d9a13b; }

/* 地図：決戦ステージ */
.map-node.battle img { filter: drop-shadow(0 0 6px rgba(255, 60, 60, .8)); }
.map-node.battle .map-state { background: #d8342c; color: #fff; }

/* ふつうの村では、目標人数は列のそばの看板に出すので、上は村の名前だけ */
.goal.nobar .goal-track, .goal.nobar #goal-num { display: none; }
.goal.nobar .goal-top { margin-bottom: 0; }
