/* ============================================
   かたちパズル - スタイル
   ============================================ */

* {
  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, #f0f4ff 0%, #d2e8fc 50%, #9fc4f0 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: #7a8fa0;
  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-shapes {
  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: #3a6ee8;
  text-align: center;
  line-height: 1.3;
  text-shadow: 2px 2px 0 rgba(58, 110, 232, 0.15);
}

.home-subtitle {
  color: #7a8fa0;
  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, #6b9bff, #3a6ee8);
  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(58, 110, 232, 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(58, 110, 232, 0.45);
}

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

/* レベル選択（1行に並べて広げる） */

.level-select {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: nowrap;
  justify-content: center;
  width: 100%;
  max-width: 520px;
}

.btn-level {
  flex: 1;
  background: #fff;
  border: 3px solid #c2d5ff;
  border-radius: 16px;
  padding: 0.8rem 0.5rem;
  font-family: inherit;
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  font-weight: 700;
  color: #3a5cb8;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 0;
  line-height: 1.35;
}

.btn-level.active {
  background: #3a6ee8;
  border-color: #3a6ee8;
  color: #fff;
  box-shadow: 0 4px 12px rgba(58, 110, 232, 0.35);
}

.btn-level:not(.active):hover {
  border-color: #769aff;
  background: #f0f5ff;
}

.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.3rem;
}

.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: #7a8fa0;
  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: #7a8fa0;
}

.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, #76a0ff, #3a6ee8);
  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: #3a6ee8;
  flex-shrink: 0;
}

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

/* ===== パズル盤面 ===== */

.board-area {
  width: 100%;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 0.8rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#board-svg {
  width: 100%;
  max-height: 36vh;
}

/* ===== ピーストレイ ===== */

.pieces-tray {
  width: 100%;
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 20px;
  min-height: 90px;
  align-items: center;
  touch-action: none;
}

.piece {
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s ease, filter 0.15s ease;
  filter: drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.15));
}

.piece:hover {
  transform: scale(1.08);
  filter: drop-shadow(3px 5px 8px rgba(0, 0, 0, 0.25));
}

.piece.dragging {
  cursor: grabbing;
  opacity: 0.85;
  filter: drop-shadow(4px 8px 12px rgba(0, 0, 0, 0.3));
  z-index: 1000;
}

.piece.placed {
  pointer-events: none;
  cursor: default;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* ===== スロット（穴） ===== */

.slot-outline {
  transition: all 0.2s ease;
}

.slot-outline.highlight {
  filter: brightness(1.3);
  stroke-width: 4;
}

.slot-filled {
  animation: slotPop 0.4s ease;
}

/* タングラム：むずかしい用のシルエット背景 */
.tangram-silhouette {
  pointer-events: none;
}
.tangram-slot path.slot-filled {
  pointer-events: none;
}

@keyframes slotPop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== フィードバック ===== */

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

.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: #3a6ee8;
  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: #7a8fa0;
  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 #c2d5ff;
  border-radius: 20px;
  padding: 0.9rem 1.6rem;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  color: #3a5cb8;
  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, #6b9bff, #3a6ee8);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 16px rgba(58, 110, 232, 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;
}

/* ===== ドラッグ中のゴースト（トレイ外で表示） ===== */

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 500;
  filter: drop-shadow(4px 8px 12px rgba(0, 0, 0, 0.3));
  transition: none;
}

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

@media (max-height: 650px) {
  .home-mascot { font-size: 3rem; margin: 0.8rem 0; }
  .home-title { font-size: 1.8rem; }
  .board-area { padding: 0.5rem; }
  #board-svg { max-height: 28vh; }
  .pieces-tray { min-height: 70px; padding: 0.5rem; gap: 0.5rem; }
  .screen { padding: 0.6rem; }
  .feedback { font-size: 1.4rem; min-height: 2rem; }
}
