/* ============================================
   クマちゃんのザルツブルガーノッケルン作り
   ============================================ */

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

:root {
  --pink: #ffd9e0;
  --pink-deep: #ffb3c1;
  --cream: #fff8ec;
  --brown: #c89876;
  --brown-deep: #a87856;
  --brown-light: #f0d4a8;
  --yellow: #ffe599;
  --red: #d94c5c;
  --text: #4a3525;
  --shadow: 0 4px 12px rgba(150, 80, 60, 0.18);
}

html, body {
  height: 100%;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #ffe9ec 0%, #ffd9e0 50%, #ffefdb 100%);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ===== 画面切り替え ===== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}
.screen.active {
  display: flex;
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ボタン ===== */
.btn {
  display: inline-block;
  margin: 6px 0;
  padding: 12px 22px;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: var(--shadow);
}
.btn:active { transform: translateY(2px) scale(0.98); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { background: rgba(255,255,255,0.85); color: var(--text); border: 2px solid var(--brown-light); }
.btn.big { padding: 16px 30px; font-size: 18px; }
.btn.small { padding: 8px 14px; font-size: 13px; }

/* ===== カード ===== */
.card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: 100%;
  width: 100%;
}
.card.center { text-align: center; }
.card h2 { font-size: 20px; margin: 8px 0 10px; color: var(--red); }
.card h3 { font-size: 16px; margin: 12px 0 6px; color: var(--brown-deep); }
.bullets { list-style: none; padding: 0; }
.bullets li { padding: 5px 0 5px 22px; position: relative; line-height: 1.5; font-size: 14px; }
.bullets li::before { content: "🐻"; position: absolute; left: 0; }
.bullets.small li { font-size: 13px; }
.bullets.small li::before { content: "・"; }
.recipe { background: #fff8ec; border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.memo { margin-top: 8px; background: #fff5d4; padding: 8px; border-radius: 8px; font-size: 13px; }

/* ===== タイトル画面 ===== */
#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}
.title-bg {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}
.game-title {
  margin: 18px 0 10px;
  line-height: 1.3;
  color: var(--text);
  text-shadow: 2px 2px 0 #fff;
}
.title-sub { display: block; font-size: 16px; }
.title-main {
  display: block;
  font-size: 30px;
  color: var(--red);
  margin: 4px 0;
  font-weight: bold;
}
.hi-score { margin-top: 14px; font-size: 13px; color: var(--brown-deep); }

/* ===== ゲーム画面 ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.85);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: bold;
  box-shadow: var(--shadow);
}
.stage-num { font-size: 22px; color: var(--red); }
.stage-name { margin-left: 8px; color: var(--brown-deep); }

.bear-mini-stage {
  height: 130px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: 6px 0;
  position: relative;
}
.bear-bubble {
  position: absolute;
  top: 4px;
  right: 8px;
  background: #fff;
  border: 2px solid var(--brown-light);
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  max-width: 60%;
  text-overflow: ellipsis;
  overflow: hidden;
  z-index: 5;
}
.bear-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 14px;
  border: 6px solid transparent;
  border-top-color: #fff;
}

.stage-instruction {
  background: rgba(255,255,255,0.92);
  border-radius: 14px;
  padding: 10px 14px;
  margin: 4px 0 8px;
  box-shadow: var(--shadow);
}
.stage-instruction h2 { font-size: 17px; color: var(--red); margin-bottom: 4px; }
.stage-instruction p { font-size: 13px; line-height: 1.5; }
.recipe-hint { background: #fff5d4; border-radius: 8px; padding: 6px 10px; margin-top: 6px; font-size: 12px; }

.play-area {
  flex: 1;
  background: rgba(255,255,255,0.55);
  border-radius: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(150,80,60,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.game-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.stage-score-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.85);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: bold;
  box-shadow: var(--shadow);
}
.bar { flex: 1; height: 12px; background: #f0e0d0; border-radius: 6px; overflow: hidden; }
.fill { height: 100%; background: linear-gradient(90deg, #ffb3c1, var(--red)); border-radius: 6px; transition: width 0.3s; width: 0%; }

/* ===== ステージ間 / 結果 ===== */
.big-score { font-size: 36px; font-weight: bold; color: var(--red); margin: 10px 0; }
.rank {
  font-size: 80px;
  font-weight: bold;
  color: var(--red);
  text-shadow: 4px 4px 0 #fff, 6px 6px 0 var(--brown-light);
  margin: 10px 0;
  animation: rankPop 0.6s ease;
  line-height: 1;
}
@keyframes rankPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}
.result-msg { font-size: 15px; margin: 10px 0; line-height: 1.5; }
.result-detail {
  text-align: left;
  background: #fff8ec;
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
  font-size: 13px;
}
.result-detail .row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed #e0c8a8; }
.result-detail .row:last-child { border: none; }

.result-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.result-top .small-bear { width: 90px; }
.result-top .rank { font-size: 64px; margin: 0; }

/* ============================================
   クマSVGキャラ — ふっくら、頭と胴体を分離、お腹ぷるぷる
   ============================================ */
.bear-mount {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
}
.bear-mount[data-bear-size="large"] { width: 200px; height: 280px; }
.bear-mount[data-bear-size="medium"] { width: 130px; height: 180px; }
.bear-mount[data-bear-size="small"] { width: 90px; height: 130px; }

.bear-svg {
  height: 100%;
  width: auto;
  max-width: 100%;
  transform-origin: bottom center;
  filter: drop-shadow(0 4px 6px rgba(150,80,40,0.15));
}

/* 歩行モード（全体上下バウンド） */
.bear-svg.walking {
  animation: bear-walk 0.7s ease-in-out infinite;
}
@keyframes bear-walk {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* 応援モード（ジャンプ） */
.bear-svg.cheering {
  animation: bear-cheer 0.55s ease-in-out infinite;
}
@keyframes bear-cheer {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-14px); }
  70% { transform: translateY(0); }
}

/* びっくりモード */
.bear-svg.shocked {
  animation: bear-shake 0.18s ease-in-out infinite;
}
@keyframes bear-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* お腹ぷるぷる */
.bear-svg .belly-anim {
  transform-box: fill-box;
  transform-origin: center;
  animation: belly-jiggle 0.55s ease-in-out infinite;
}
.bear-svg.cheering .belly-anim {
  animation: belly-bounce 0.45s ease-in-out infinite;
}
@keyframes belly-jiggle {
  0%, 100% { transform: scale(1, 1); }
  20% { transform: scale(1.06, 0.94); }
  40% { transform: scale(0.95, 1.06); }
  60% { transform: scale(1.04, 0.96); }
  80% { transform: scale(0.97, 1.03); }
}
@keyframes belly-bounce {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.13, 0.88); }
}

/* 表情切替 */
.bear-svg .eyes-happy, .bear-svg .eyes-shocked { display: none; }
.bear-svg.cheering .eyes-normal { display: none; }
.bear-svg.cheering .eyes-happy { display: inline; }
.bear-svg.shocked .eyes-normal { display: none; }
.bear-svg.shocked .eyes-shocked { display: inline; }
.bear-svg.cheering .mouth-normal { display: none; }
.bear-svg.cheering .mouth-happy { display: inline; }
.bear-svg .mouth-happy { display: none; }

/* 腕アニメ（歩行） */
.bear-svg .arm-l {
  transform-box: fill-box;
  transform-origin: top center;
  animation: arm-sway-l 1.0s ease-in-out infinite;
}
.bear-svg .arm-r {
  transform-box: fill-box;
  transform-origin: top center;
  animation: arm-sway-r 1.0s ease-in-out infinite;
}
@keyframes arm-sway-l {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(8deg); }
}
@keyframes arm-sway-r {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-8deg); }
}
.bear-svg.cheering .arm-l { animation: arm-cheer-l 0.5s ease-in-out infinite; }
.bear-svg.cheering .arm-r { animation: arm-cheer-r 0.5s ease-in-out infinite; }
@keyframes arm-cheer-l {
  0%, 100% { transform: rotate(-30deg) translateY(-30px); }
  50% { transform: rotate(-45deg) translateY(-30px); }
}
@keyframes arm-cheer-r {
  0%, 100% { transform: rotate(30deg) translateY(-30px); }
  50% { transform: rotate(45deg) translateY(-30px); }
}

/* ============================================
   ノッケルン（出来上がり）SVG
   ============================================ */
.dessert-mount {
  width: 100%;
  max-width: 320px;
  margin: 8px auto;
  background: linear-gradient(180deg, #fff5e8 0%, #ffe5c8 100%);
  border-radius: 16px;
  padding: 8px;
  box-shadow: var(--shadow);
}
.dessert-svg {
  width: 100%;
  height: auto;
  display: block;
}
.dessert-svg.fluffy { animation: dessert-float 2s ease-in-out infinite; }
@keyframes dessert-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.dessert-svg.deflated { animation: dessert-sad 3s ease-in-out infinite; }
@keyframes dessert-sad {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.97); }
}

/* ============================================
   各ステージのミニゲームUI
   ============================================ */

/* 共通：投入ボタン群 */
.ingredient-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}
.ingredient-btn {
  background: #fff;
  border: 3px solid var(--brown-light);
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 110px;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  color: var(--brown-deep);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.ingredient-btn .icon { font-size: 28px; display: block; }
.ingredient-btn .amount { font-size: 11px; color: var(--red); margin-top: 4px; }
.ingredient-btn:active { transform: scale(0.95); }
.ingredient-btn.next { background: #fff5d4; border-color: var(--red); animation: pulse 0.9s infinite; }
.ingredient-btn.done { background: #e8f5d8; border-color: #a8c878; opacity: 0.7; pointer-events: none; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.bowl-area {
  flex: 1;
  width: 100%;
  background: radial-gradient(ellipse at center, #fff8ec 30%, #ffe0b8 100%);
  border-radius: 50%;
  border: 4px solid var(--brown-deep);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 4px 12px rgba(150,80,40,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  min-height: 140px;
}
.bowl-area .bowl-content {
  text-align: center;
  font-size: 32px;
}
.bowl-area canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* メレンゲ（連打） */
.meringue-game { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 8px; }
.foam-bowl {
  flex: 1;
  background: linear-gradient(180deg, #fff 50%, #f0d4a8 100%);
  border-radius: 50% 50% 20px 20px / 25% 25% 20px 20px;
  border: 4px solid var(--brown-deep);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 4px 12px rgba(0,0,0,0.15);
  min-height: 120px;
}
.foam {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, #fff 0%, #fff8e8 80%, #f0e0c8 100%);
  transition: height 0.15s ease-out;
  height: 0%;
}
.foam::before {
  content: "";
  position: absolute;
  top: -10px; left: 0; right: 0; height: 20px;
  background: radial-gradient(circle 8px at 10px 10px, #fff 60%, transparent 60%) repeat-x;
  background-size: 20px 20px;
}
.foam.over { background: linear-gradient(180deg, #f0e0d0 0%, #d8c0a0 100%); }

.tap-whisk-btn {
  width: 100%;
  padding: 18px;
  font-size: 18px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-weight: bold;
  font-family: inherit;
  box-shadow: var(--shadow);
}
.tap-whisk-btn:active { transform: scale(0.97); }
.tap-whisk-btn:disabled { opacity: 0.5; }

.peak-indicator {
  position: absolute;
  top: 8px; left: 8px; right: 8px;
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  z-index: 5;
}
.peak-indicator.alert { background: #fff5d4; color: var(--red); animation: shake 0.4s infinite; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.sugar-drop {
  position: absolute;
  width: 56px; height: 56px;
  background: radial-gradient(circle, #fff8ec, #f0e0c0);
  border-radius: 50%;
  border: 3px solid var(--brown-light);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  cursor: pointer;
  z-index: 10;
  animation: pulse 0.7s infinite;
}

/* 3つの山（盛り付け） */
.peaks-game { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 8px; }
.gratin-pan {
  flex: 1;
  background: radial-gradient(ellipse at center, #fff8ec 40%, #e8c898 100%);
  border-radius: 40px;
  border: 5px solid var(--brown-deep);
  position: relative;
  overflow: hidden;
  margin: 4px;
  box-shadow: inset 0 4px 12px rgba(150,80,40,0.2);
  touch-action: none;
  min-height: 160px;
}
.gratin-pan canvas { width: 100%; height: 100%; display: block; }
.peak-counter {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(255,255,255,0.92);
  border-radius: 12px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: bold;
  z-index: 5;
}

/* オーブン */
.oven-timer {
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  text-align: center;
  font-weight: bold;
  border: 3px solid var(--brown-deep);
  box-shadow: var(--shadow);
}
.oven-timer .timer-bar {
  width: 100%; height: 22px;
  background: linear-gradient(90deg,
    #ffe0e0 0%, #ffe0e0 60%,
    #c8f0a8 65%, #a8e088 75%, #a8e088 90%,
    #ff8888 95%, #ff8888 100%);
  border-radius: 11px;
  position: relative;
  margin: 6px 0;
  overflow: hidden;
  border: 2px solid var(--brown-light);
}
.oven-timer .timer-bar .timer-fill {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 0%;
  background: rgba(255,255,255,0.5);
  border-right: 3px solid var(--red);
}
.oven-timer button {
  margin-top: 6px;
  padding: 14px 26px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  font-family: inherit;
  font-family: inherit;
}

/* お知らせフラッシュ */
.flash-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95);
  border: 3px solid var(--red);
  border-radius: 14px;
  padding: 10px 20px;
  font-size: 18px;
  font-weight: bold;
  color: var(--red);
  box-shadow: var(--shadow);
  z-index: 100;
  pointer-events: none;
  animation: flash 0.8s ease-out forwards;
}
@keyframes flash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  40% { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* スマホ調整 */
@media (max-height: 700px) {
  .bear-mini-stage { height: 110px; }
  .bear-mount[data-bear-size="medium"] { width: 110px; height: 150px; }
  .stage-instruction h2 { font-size: 15px; }
  .stage-instruction p { font-size: 12px; }
  .game-title .title-main { font-size: 24px; }
  .rank { font-size: 60px; }
}
@media (max-height: 600px) {
  .bear-mini-stage { display: none; }
}
