/* ============================================================
   CNP にんじゃミッション工房 - スタイル
   ============================================================ */

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

:root {
  --bg: #fdf6e9;
  --ink: #3a3226;
  --navy: #2b3a67;
  --accent: #e17055;
  --gold: #f6b93b;
  --green: #78c850;
  --card: #ffffff;
  --radius: 16px;
}

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDGothic", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

/* ---------- トップバー ---------- */
#topbar {
  display: flex;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: var(--navy);
  color: #fff;
  justify-content: space-around;
  flex-shrink: 0;
}
.res {
  background: rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
}

/* ---------- メイン ---------- */
#screen {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 広告バー（ホーム画面のみ表示） ---------- */
#ad-bar {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #eadfc8;
  min-height: 0;
  max-height: 70px;
  overflow: hidden;
}
.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  font-size: 12px;
  color: #b3a888;
  text-align: center;
}
.ad-placeholder span { font-size: 10px; }

/* ---------- タブバー ---------- */
#tabbar {
  display: flex;
  flex-shrink: 0;
  background: #fff;
  border-top: 2px solid #eadfc8;
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0 6px;
  font-size: 11px;
  color: #9a8f7a;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: inherit;
  cursor: pointer;
}
#tabbar button .ticon { font-size: 22px; }
#tabbar button.active { color: var(--navy); font-weight: bold; }
#tabbar button.active .ticon { transform: scale(1.15); }

/* ---------- ボタン ---------- */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  font-family: inherit;
  padding: 14px;
  margin: 8px 0;
  cursor: pointer;
  box-shadow: 0 4px 0 #c05a42;
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c05a42; }
.btn.big { font-size: 18px; padding: 16px; }
.btn.small { width: auto; font-size: 14px; padding: 9px 16px; margin: 4px 0; box-shadow: 0 3px 0 #c05a42; }
.btn.ghost { background: #fff; color: var(--navy); box-shadow: 0 3px 0 #d9cdb4; border: 2px solid #e5dac2; }
.btn.danger { background: #d63031; box-shadow: 0 3px 0 #a02324; }
.btn:disabled { opacity: .55; }

/* ---------- ホーム ---------- */
.chapter-banner {
  background: var(--navy);
  color: #ffe9a8;
  text-align: center;
  border-radius: var(--radius);
  padding: 10px;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 12px;
}
.partner-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.partner-face {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
  background: #fff;
}
.bubble {
  background: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.bubble::before {
  content: "";
  position: absolute;
  left: -8px; top: 22px;
  border: 6px solid transparent;
  border-right-color: #fff;
}
.home-stats { text-align: center; font-size: 13px; color: #8d8064; margin: 6px 0; }

/* ---------- 里グリッド ---------- */
.village-wrap {
  background: linear-gradient(160deg, #d4e7b5, #b8d98d);
  border-radius: var(--radius);
  padding: 8px;
  border: 3px solid #a3c76d;
}
.village { display: grid; gap: 3px; }
.vcell {
  aspect-ratio: 1;
  background: rgba(255,255,255,.35);
  border: none;
  border-radius: 6px;
  font-size: clamp(16px, 5.5vw, 26px);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.vcell.filled { background: rgba(255,255,255,.7); }
button.vcell:active { background: rgba(255,255,255,.9); }

/* ---------- 任務 ---------- */
.page-title { font-size: 18px; font-weight: bold; margin: 4px 0 10px; }
.page-title .date { font-size: 12px; color: #9a8f7a; font-weight: normal; }
.ai-note {
  background: #fff4d6;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: #8a6d1d;
  margin-bottom: 12px;
}
.mission-list { display: flex; flex-direction: column; gap: 10px; }
.mission-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.mission-card.done { opacity: .65; }
.m-icon { font-size: 30px; }
.m-body { flex: 1; }
.m-label { font-weight: bold; font-size: 15px; }
.m-story { font-size: 12.5px; color: #8d8064; }
.m-special {
  background: var(--gold);
  color: #fff;
  border-radius: 999px;
  font-size: 10.5px;
  padding: 2px 8px;
}
.m-hard {
  background: #d63031;
  color: #fff;
  border-radius: 999px;
  font-size: 10.5px;
  padding: 2px 8px;
}
.mission-card.hard { border: 2px solid #ff7675; }
.no-support {
  background: #ffe3e3;
  color: #a02324;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: bold;
  text-align: center;
  margin: 8px 0;
}
.m-done { font-size: 22px; }

.day-end {
  text-align: center;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 14px;
  margin-bottom: 14px;
}
.day-end-emoji { font-size: 44px; }
.day-end-title { font-size: 18px; font-weight: bold; margin: 8px 0 4px; }
.day-end-sub { font-size: 13px; opacity: .9; line-height: 1.7; }

/* ---------- プレイ画面 ---------- */
.play-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.play-title { font-weight: bold; font-size: 16px; }
.puzzle-area {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 10px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.qtext { font-size: 16px; line-height: 1.8; font-weight: bold; margin-bottom: 12px; }
.qtext .sub { font-size: 12.5px; color: #8d8064; font-weight: normal; }

.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice {
  border: 2px solid #e5dac2;
  background: #fffdf7;
  border-radius: 12px;
  padding: 13px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}
.choice:active { background: #fff1d6; }
.choice.dim { opacity: .45; }
.choice.tile { display: inline-flex; width: 52px; height: 52px; align-items: center; justify-content: center; font-size: 20px; }

.hint-area { margin: 6px 0; }
.hint-line {
  background: #e8f4fd;
  color: #1e6091;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 6px 0;
}

/* すいり */
.deduce-hints { margin: 8px 0; }
.deduce-hint {
  background: #f0ead6;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  margin: 6px 0;
}

/* じゅんばん */
.order-seq {
  background: #f7f2e4;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  min-height: 44px;
  margin-bottom: 10px;
  line-height: 1.9;
}
.order-list { display: flex; flex-direction: column; gap: 8px; }

/* きおく */
.scroll-view {
  background: linear-gradient(#f9edcf, #f3e2b3);
  border: 3px solid #cbb26a;
  border-radius: 12px;
  text-align: center;
  font-size: 34px;
  padding: 22px 10px;
  letter-spacing: 8px;
}
.mem-timer { text-align: center; font-size: 26px; font-weight: bold; color: var(--accent); margin: 8px 0; min-height: 32px; }

/* かんさつ */
.obs-grid { display: grid; gap: 6px; }
.obs-cell {
  aspect-ratio: 1;
  font-size: clamp(20px, 6.5vw, 30px);
  background: #fffdf7;
  border: 2px solid #eee3ca;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  cursor: pointer;
}

/* めいろ */
.maze { display: grid; gap: 0; border-radius: 10px; overflow: hidden; margin: 8px 0; }
.mz-cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: clamp(10px, 3.4vw, 18px); }
.mz-cell.wall { background: var(--navy); }
.mz-cell.floor { background: #fdf3da; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
}
.dbtn {
  height: 52px;
  font-size: 22px;
  border: none;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 #1d2947;
}
.dbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1d2947; }

/* あんごう */
.cipher-key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.key-item {
  background: #f0ead6;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 15px;
  font-weight: bold;
}
.cipher-code {
  text-align: center;
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 4px;
  background: #fdf3da;
  border-radius: 12px;
  padding: 14px;
  margin: 8px 0;
}

/* ことばならべ */
.anag-slots { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
.anag-slot {
  width: 48px; height: 48px;
  border: 2px dashed #cbb26a;
  border-radius: 10px;
  background: #fffdf7;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: bold;
}
.anag-tiles { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }

/* ---------- 結果・モーダル ---------- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(43,58,103,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
#overlay.hidden { display: none; }
.modal {
  background: var(--bg);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 82vh;
  max-height: 82dvh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.result { text-align: center; }
.result-emoji { font-size: 54px; }
.result-title { font-size: 20px; font-weight: bold; margin: 8px 0; }
.result-line { font-size: 14px; line-height: 1.8; color: #6d6250; margin: 6px 0 12px; }
.result-rewards { margin: 12px 0; }
.reward-item {
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  font-weight: bold;
  margin: 6px 0;
}

/* ---------- なかま ---------- */
.char-list { display: flex; flex-direction: column; gap: 10px; }
.char-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  border: 3px solid transparent;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.char-card.locked { opacity: .8; }
.char-face {
  width: 54px; height: 54px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  flex-shrink: 0;
}
.char-body { flex: 1; }
.char-name { font-weight: bold; font-size: 16px; }
.char-role { font-size: 12px; color: #8d8064; }
.char-action { flex-shrink: 0; max-width: 40%; }
.char-current { font-size: 11.5px; color: var(--green); font-weight: bold; text-align: center; }
.char-card.pickable { cursor: pointer; }
.char-card.pickable:active { background: #fff6e0; }

/* ---------- おみせ ---------- */
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 2px solid #eee3ca;
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  color: var(--ink);
}
.shop-item.cant { opacity: .5; }
.s-emoji { font-size: 26px; }
.s-body { flex: 1; font-size: 13px; }
.s-body small { color: #8d8064; }
.s-cost { font-size: 12.5px; font-weight: bold; white-space: nowrap; }
.inv-bar {
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 10px 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.05);
}

/* ---------- 保護者 ---------- */
.parent-gate { background: #fff; border-radius: var(--radius); padding: 18px; text-align: center; }
.gate-q { font-size: 22px; font-weight: bold; }
.gate-input {
  width: 120px;
  font-size: 22px;
  text-align: center;
  padding: 10px;
  border: 2px solid #e5dac2;
  border-radius: 12px;
  font-family: inherit;
}
.gate-msg { color: #d63031; font-size: 13px; min-height: 20px; margin-top: 6px; }
.parent-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
.parent-box label { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; gap: 10px; }
.parent-box select {
  font-size: 14px;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid #e5dac2;
  font-family: inherit;
  background: #fffdf7;
}
.parent-box.safety { font-size: 12.5px; color: #6d6250; }
.parent-box.safety ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.9; }
.stat-line { margin: 4px 0; }
.install-steps { text-align: left; font-size: 14px; line-height: 2; padding-left: 20px; }
.install-body p { font-size: 13px; }

/* ---------- エフェクト ---------- */
.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.pop { animation: pop .3s; }
@keyframes pop {
  0% { transform: scale(.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.glow {
  box-shadow: 0 0 0 3px var(--gold), 0 0 16px var(--gold) !important;
  background: #fff3c4 !important;
}
.confetti {
  position: fixed;
  top: -30px;
  z-index: 100;
  pointer-events: none;
  animation: fall 2.4s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(360deg); opacity: .6; }
}
