/* ============================================
   はじめてのたしざん - スタイル
   ============================================ */

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

body {
  font-family: "M PLUS Rounded 1c", "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  min-height: 100dvh;
  background: linear-gradient(135deg, #fff8f0 0%, #ffecd2 50%, #fcb69f 100%);
  overflow: hidden;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== 戻るボタン ===== */

.btn-back-hub {
  position: fixed;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 100;
  text-decoration: none;
  color: #a0887a;
  font-size: 0.85rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.4rem 0.8rem;
  border-radius: 12px;
}

/* ===== 画面共通 ===== */

.app-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1rem;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ホーム画面 ===== */

.home-fruits {
  font-size: 2rem;
  letter-spacing: 0.5rem;
  margin-bottom: 0.5rem;
  animation: float 3s ease-in-out infinite;
}

.home-title {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 900;
  color: #e8553a;
  text-align: center;
  line-height: 1.3;
  text-shadow: 2px 2px 0 rgba(232, 85, 58, 0.15);
}

.home-subtitle {
  color: #a0887a;
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  font-weight: 700;
  margin-top: 0.5rem;
  text-align: center;
}

.home-mascot {
  font-size: 4rem;
  margin: 1.5rem 0;
}

.bounce {
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.btn-play {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: #fff;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 900;
  padding: 1rem 3rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(238, 90, 36, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.1em;
}

.btn-play:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 28px rgba(238, 90, 36, 0.45);
}

.btn-play:active {
  transform: scale(0.97);
}

/* レベル選択 */

.level-select {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-level {
  background: #fff;
  border: 3px solid #ffd5c2;
  border-radius: 16px;
  padding: 0.8rem 1.1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #b85c3a;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 110px;
  line-height: 1.4;
}

.btn-level.active {
  background: #ff6b6b;
  border-color: #ff6b6b;
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.35);
}

.btn-level:not(.active):hover {
  border-color: #ff9a76;
  background: #fff5f0;
}

.level-range {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.8;
}

/* ===== ゲーム画面 ===== */

.game-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
}

.btn-back {
  background: rgba(255, 255, 255, 0.6);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0887a;
  font-weight: 700;
  flex-shrink: 0;
}

.progress-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.progress-label {
  font-size: 1rem;
  font-weight: 700;
  color: #a0887a;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff9a76, #ff6b6b);
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0%;
}

.score-area {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 1.4rem;
  font-weight: 900;
  color: #e8553a;
  flex-shrink: 0;
}

.score-star {
  font-size: 1.5rem;
}

/* 問題エリア */

.question-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 1.2rem 1.5rem;
  width: 100%;
  min-height: 130px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  margin-bottom: 0.8rem;
}

.fruit-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.fruit-item {
  font-size: clamp(2rem, 8vw, 2.8rem);
  animation: popIn 0.3s ease backwards;
  filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.1));
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.operator {
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 900;
  color: #e8553a;
  flex-shrink: 0;
}

/* 式テキスト */

.equation-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 900;
  color: #5a3e2e;
  margin-bottom: 1rem;
}

.eq-op {
  color: #e8553a;
}

.eq-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 3px dashed #ffc4a0;
  border-radius: 16px;
  min-width: 2.5em;
  padding: 0.1em 0.4em;
  color: #e8553a;
  transition: all 0.3s ease;
}

.eq-answer.solved {
  border-style: solid;
  border-color: #4ecdc4;
  background: #e8fff9;
  color: #2a9d8f;
}

/* 選択肢 */

.choices {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.choice-btn {
  background: #fff;
  border: 3px solid #ffd5c2;
  border-radius: 22px;
  min-width: 85px;
  min-height: 85px;
  font-family: inherit;
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  font-weight: 900;
  color: #5a3e2e;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  padding: 0.6rem 1.5rem;
}

.choice-btn:hover {
  transform: scale(1.08);
  border-color: #ff9a76;
}

.choice-btn:active {
  transform: scale(0.95);
}

.choice-btn.correct {
  background: linear-gradient(135deg, #4ecdc4, #44bd99);
  border-color: #4ecdc4;
  color: #fff;
  animation: correctPop 0.4s ease;
  box-shadow: 0 6px 20px rgba(78, 205, 196, 0.4);
}

@keyframes correctPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.choice-btn.wrong {
  background: #ffe0e0;
  border-color: #ff8a8a;
  color: #d63031;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-4px); }
}

.choice-btn:disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* フィードバック */

.feedback {
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feedback.correct-feedback {
  color: #2a9d8f;
  animation: feedbackPop 0.5s ease;
}

.feedback.wrong-feedback {
  color: #e17055;
  animation: feedbackPop 0.5s ease;
}

@keyframes feedbackPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== けっか画面 ===== */

.result-emoji {
  font-size: 5rem;
  animation: bounce 1.5s ease-in-out infinite;
}

.result-title {
  font-size: clamp(1.8rem, 7vw, 2.5rem);
  font-weight: 900;
  color: #e8553a;
  margin: 0.5rem 0;
}

.result-stars {
  font-size: 2.5rem;
  letter-spacing: 0.3rem;
  margin: 0.5rem 0;
}

.result-message {
  font-size: 1.3rem;
  font-weight: 700;
  color: #a0887a;
  text-align: center;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.result-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-result {
  background: #fff;
  border: 3px solid #ffd5c2;
  border-radius: 20px;
  padding: 0.9rem 1.6rem;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  color: #b85c3a;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn-result:hover {
  transform: scale(1.05);
}

.btn-result:active {
  transform: scale(0.97);
}

.btn-result.primary {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 16px rgba(238, 90, 36, 0.3);
}

.btn-icon {
  font-size: 1.2em;
}

/* ===== 紙吹雪 Canvas ===== */

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}

/* ===== レスポンシブ ===== */

@media (max-height: 650px) {
  .home-mascot { font-size: 3rem; margin: 0.8rem 0; }
  .home-title { font-size: 1.8rem; }
  .question-area { min-height: 90px; padding: 0.8rem; }
  .fruit-item { font-size: 1.5rem; }
  .screen { padding: 0.6rem; }
}
