/* ===========================
   リセット & ベース
=========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --pink:    #f9a8d4;
  --lavender:#c4b5fd;
  --sky:     #7dd3fc;
  --mint:    #a7f3d0;
  --yellow:  #fde68a;
  --white:   #ffffff;
  --navy:    #1e293b;
  --gray:    #64748b;

  --radius-lg: 24px;
  --radius-md: 16px;

  --shadow:    0 8px 32px rgba(200, 150, 255, 0.18);
  --shadow-sm: 0 4px 12px rgba(200, 150, 255, 0.12);

  --font: 'M PLUS Rounded 1c', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: linear-gradient(160deg, #fff0fb 0%, #f0e8ff 50%, #e8f4ff 100%);
  color: var(--navy);
  overflow-x: hidden;
}

/* ===========================
   画面共通
=========================== */
.screen {
  display: none;
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===========================
   背景デコレーション
=========================== */
.bg-deco {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(196,181,253,0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(196,181,253,0.1) 1px, transparent 1px);
  background-size: 48px 48px;
}

.bg-deco::before,
.bg-deco::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  opacity: 0.15;
  animation: drift 12s ease-in-out infinite alternate;
}

.bg-deco::before {
  width: 420px; height: 420px;
  background: #f9a8d4;
  top: -100px; left: -100px;
}

.bg-deco::after {
  width: 320px; height: 320px;
  background: #c4b5fd;
  bottom: -80px; right: -80px;
  animation-delay: -6s;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(30px, 20px) scale(1.05); }
}

/* ===========================
   キラキラ星
=========================== */
.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

/* ===========================
   ストーリー画面
=========================== */
/* ===========================
   ストーリー画面レイアウト
   上半分：画像　下半分：テキスト
=========================== */
#screen-story {
  justify-content: flex-start;
  align-items: stretch;
  background: #1a1128;
}

/* 上半分：画像エリア */
.story-image-area {
  flex: 0 0 auto;
  height: 42dvh;
  max-height: 42dvh;
  overflow: hidden;
  position: relative;
  background: #0d0a1a;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ストーリー画像 */
.story-img {
  width: 100%;
  height: 100%;
  object-fit: contain;   /* 縦横比を保ったまま全体を収める */
  object-position: center;
  display: block;
  opacity: 0;
  transition: opacity 0.5s ease-out;
}

.story-img.is-visible {
  opacity: 1;
}

/* 下半分：テキストボックス */
.story-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 28px 28px;
  background: linear-gradient(170deg, #2d1b4e 0%, #1a1128 100%);
  border-top: 2px solid rgba(196,181,253,0.3);
}

/* ストーリー本文 */
.story-text {
  font-size: clamp(0.95rem, 3.2vw, 1.1rem);
  font-weight: 700;
  color: #f0e8ff;
  line-height: 2;
  white-space: pre-wrap;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.45s ease-out, transform 0.45s ease-out;
  flex: 1;
}

.story-text.text-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ナビ（進捗＋次へボタン） */
.story-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  flex-shrink: 0;
}

/* ページ進捗 */
.story-progress {
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(196,181,253,0.7);
  letter-spacing: 0.06em;
}

/* 次へボタン */
.btn-story-next {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 800;
  font-family: var(--font);
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #a78bfa);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 16px rgba(139,92,246,0.45);
}

.btn-story-next:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 20px rgba(139,92,246,0.6);
}

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

.story-arrow {
  font-size: 0.85rem;
}

/* スキップボタン */
.btn-story-skip {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  padding: 8px 18px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--font);
  color: rgba(196,181,253,0.85);
  background: rgba(45,27,78,0.7);
  border: 1px solid rgba(196,181,253,0.3);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  backdrop-filter: blur(6px);
}

.btn-story-skip:hover {
  background: rgba(139,92,246,0.6);
  color: #fff;
}

/* スマホ対応 */
@media (max-width: 480px) {
  .story-image-area {
    height: 36dvh;
    max-height: 36dvh;
  }
  .story-box {
    padding: 18px 20px 24px;
  }
  .story-text {
    font-size: 0.92rem;
    line-height: 1.85;
  }
  .btn-story-next {
    padding: 10px 24px;
    font-size: 0.95rem;
  }
}

/* ===========================
   スタート画面
=========================== */
.start-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 24px 60px;
  max-width: 480px;
  width: 100%;
}

.game-title {
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 800;
  color: #7c3aed;
  text-shadow:
    0 0 20px rgba(167, 139, 250, 0.6),
    0 3px 0 #5b21b6,
    0 6px 12px rgba(0,0,0,0.1);
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.title-deco {
  font-size: 1.4rem;
  color: #a78bfa;
  filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.8));
  animation: twinkle 2s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.7; transform: scale(0.9); }
  to   { opacity: 1;   transform: scale(1.1); }
}

.game-subtitle {
  font-size: 0.97rem;
  color: rgba(30, 41, 59, 0.7);
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.7;
}

.subtitle-note {
  font-size: 0.85rem;
  color: #7c3aed;
  font-weight: 700;
}

.info-badges {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.info-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: default;
  user-select: none;
}

.badge-hint {
  background: linear-gradient(135deg, #fef3c7, #fffbeb);
  color: #92400e;
  border: 2px solid #fde68a;
  box-shadow: 0 4px 14px rgba(253,230,138,0.3);
}

.badge-branch {
  background: linear-gradient(135deg, #ede9fe, #f5f3ff);
  color: #5b21b6;
  border: 2px solid #c4b5fd;
  box-shadow: 0 4px 14px rgba(196,181,253,0.3);
}

/* スタートボタン */
.btn-primary {
  position: relative;
  padding: 16px 48px;
  font-size: 1.25rem;
  font-weight: 800;
  font-family: var(--font);
  color: var(--white);
  background: linear-gradient(135deg, #8b5cf6, #a78bfa);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 24px rgba(139,92,246,0.45), 0 2px 0 #5b21b6 inset;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.btn-primary:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 10px 32px rgba(139,92,246,0.55), 0 2px 0 #5b21b6 inset;
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.shine-btn::after {
  content: '';
  position: absolute;
  top: 0; left: -75%;
  width: 50%; height: 100%;
  background: linear-gradient(to right, transparent, rgba(255,255,255,0.35), transparent);
  transform: skewX(-20deg);
  animation: shine 3s ease-in-out infinite;
}

@keyframes shine {
  0%   { left: -75%; opacity: 0; }
  30%  { opacity: 1; }
  60%  { left: 130%; opacity: 0; }
  100% { left: 130%; opacity: 0; }
}

/* ===========================
   ゲーム画面
=========================== */
#screen-game {
  align-items: stretch;
  justify-content: flex-start;
  padding-bottom: 60px;
}

/* ナビ */
.question-nav {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 16px 20px;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(12px);
  border-bottom: 2px solid rgba(196,181,253,0.4);
  flex-wrap: wrap;
}

.nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  font-size: 0.85rem;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1;
}

.nav-btn-label {
  font-size: 0.62rem;
  font-weight: 700;
}

.nav-btn.state-current {
  background: linear-gradient(135deg, #8b5cf6, #a78bfa);
  color: white;
  border-color: #5b21b6;
  box-shadow: 0 4px 14px rgba(139,92,246,0.4);
  transform: scale(1.1);
  cursor: default;
}

.nav-btn.state-done {
  background: linear-gradient(135deg, #bbf7d0, #d1fae5);
  color: #047857;
  border-color: #6ee7b7;
  box-shadow: 0 3px 10px rgba(110,231,183,0.3);
}

.nav-btn.state-done:hover {
  transform: scale(1.08);
}

.nav-btn.state-locked {
  background: rgba(255,255,255,0.6);
  color: #94a3b8;
  border-color: #e2e8f0;
  cursor: not-allowed;
  opacity: 0.6;
}

/* ゲームメイン */
.game-main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px 20px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* 問題画像 */
.question-image-wrap {
  position: relative;
  width: 100%;
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 3px solid rgba(196,181,253,0.5);
  min-height: 80px;
}

.question-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.question-image.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* 分岐バッジ */
.branch-badge {
  width: 100%;
  max-width: 480px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  animation: feedbackPop 0.3s ease-out;
}

.branch-badge.route-a {
  background: linear-gradient(135deg, #ede9fe, #ddd6fe);
  color: #5b21b6;
  border: 2px solid #a78bfa;
}

.branch-badge.route-b {
  background: linear-gradient(135deg, #fce7f3, #fbcfe8);
  color: #9d174d;
  border: 2px solid #f9a8d4;
}

/* 閲覧モード：過去の答え表示 */
.review-answer-box {
  width: 100%;
  background: linear-gradient(135deg, #d1fae5, #ecfdf5);
  border: 2.5px solid #6ee7b7;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #065f46;
  box-shadow: 0 4px 14px rgba(110,231,183,0.25);
}

.review-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #059669;
  white-space: nowrap;
}

.review-answer-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: #047857;
  letter-spacing: 0.06em;
}

.review-correct-mark {
  margin-left: auto;
  font-size: 0.9rem;
  color: #10b981;
  white-space: nowrap;
}

.hidden { display: none !important; }

/* 答え入力 */
.answer-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.answer-form {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.answer-input {
  flex: 1;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-family: var(--font);
  font-weight: 700;
  border: 2.5px solid rgba(196,181,253,0.6);
  border-radius: 999px;
  outline: none;
  background: rgba(255,255,255,0.9);
  color: var(--navy);
  transition: border-color 0.2s, box-shadow 0.2s;
  text-align: center;
  letter-spacing: 0.05em;
}

.answer-input:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 4px rgba(167,139,250,0.2);
  background: white;
}

.answer-input.shake {
  animation: shakeInput 0.4s ease-out;
}

.answer-input.glow-correct {
  border-color: #6ee7b7;
  box-shadow: 0 0 0 4px rgba(110,231,183,0.3);
}

.answer-input.glow-wrong {
  border-color: #fca5a5;
  box-shadow: 0 0 0 4px rgba(252,165,165,0.3);
}

@keyframes shakeInput {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.btn-submit {
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 800;
  font-family: var(--font);
  color: white;
  background: linear-gradient(135deg, #8b5cf6, #a78bfa);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(139,92,246,0.35);
}

.btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(139,92,246,0.45);
}

/* フィードバック */
.feedback {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  width: 100%;
  max-width: 480px;
  animation: feedbackPop 0.3s ease-out;
}

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

.feedback.correct {
  background: linear-gradient(135deg, #bbf7d0, #d1fae5);
  color: #065f46;
  border: 2px solid #6ee7b7;
}

.feedback.wrong {
  background: linear-gradient(135deg, #fecaca, #fee2e2);
  color: #991b1b;
  border: 2px solid #fca5a5;
}

/* ヒント */
.hint-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  font-size: 0.92rem;
  font-weight: 700;
  font-family: var(--font);
  color: #92400e;
  background: linear-gradient(135deg, #fef3c7, #fffbeb);
  border: 2px solid #fde68a;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(253,230,138,0.3);
}

.btn-hint:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(253,230,138,0.45);
}

.hint-box {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(135deg, #fef3c7, #fffbeb);
  border: 2px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: 0 4px 14px rgba(253,230,138,0.3);
  animation: hintOpen 0.25s ease-out;
}

@keyframes hintOpen {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hint-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: #92400e;
  margin-bottom: 8px;
}

.hint-text {
  font-size: 1rem;
  font-weight: 700;
  color: #78350f;
  line-height: 1.7;
}

/* ===========================
   クリア画面
=========================== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  border-radius: 3px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

.clear-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 48px 24px 60px;
  max-width: 480px;
  width: 100%;
}

.clear-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.clear-top-image {
  width: 220px;
  height: 220px;
  object-fit: cover;
  border-radius: 16px;
  border: 4px solid #a78bfa;
  box-shadow: 0 6px 24px rgba(139,92,246,0.3);
  animation: trophyBounce 0.8s cubic-bezier(0.2, 0.6, 0.3, 1.5) both;
}

@keyframes trophyBounce {
  from { opacity: 0; transform: scale(0.4) translateY(-30px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.clear-title {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  color: #7c3aed;
  text-shadow:
    0 0 20px rgba(167,139,250,0.6),
    0 3px 0 #5b21b6,
    0 6px 12px rgba(0,0,0,0.12);
  letter-spacing: 0.1em;
}

.clear-subtitle {
  font-size: 1.05rem;
  color: rgba(30,41,59,0.6);
  font-weight: 700;
}

/* ルートバッジ */
.route-badge {
  padding: 8px 24px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 800;
}

.route-badge.route-a {
  background: linear-gradient(135deg, #ede9fe, #ddd6fe);
  color: #5b21b6;
  border: 2px solid #a78bfa;
}

.route-badge.route-b {
  background: linear-gradient(135deg, #fce7f3, #fbcfe8);
  color: #9d174d;
  border: 2px solid #f9a8d4;
}

/* 結果カード */
.result-cards {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.result-card {
  flex: 1;
  min-width: 110px;
  max-width: 160px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  padding: 18px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 2px solid rgba(196,181,253,0.3);
  animation: cardPop 0.5s cubic-bezier(0.2, 0.6, 0.3, 1.4) both;
}

.result-card:nth-child(2) { animation-delay: 0.1s; }
.result-card:nth-child(3) { animation-delay: 0.2s; }

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.8) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.result-icon { font-size: 1.6rem; }
.result-label { font-size: 0.78rem; font-weight: 700; color: var(--gray); }
.result-value { font-size: 1.5rem; font-weight: 800; color: var(--navy); }
.result-unit  { font-size: 0.85rem; color: var(--gray); font-weight: 700; }

.rank-badge { font-size: 2rem; font-weight: 800; }
.rank-s { color: #f59e0b; text-shadow: 0 0 16px rgba(245,158,11,0.6); }
.rank-a { color: #22c55e; text-shadow: 0 0 16px rgba(34,197,94,0.6); }
.rank-b { color: #38bdf8; text-shadow: 0 0 16px rgba(56,189,248,0.6); }
.rank-c { color: #94a3b8; }

/* クリアボタン */
.clear-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.btn-share-x {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 800;
  font-family: var(--font);
  color: white;
  background: #000;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}

.btn-share-x:hover {
  background: #333;
  transform: translateY(-2px);
}

.btn-retry {
  width: 100%;
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font);
  color: #5b21b6;
  background: rgba(255,255,255,0.82);
  border: 2px solid #a78bfa;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}

.btn-retry:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(167,139,250,0.35);
}

/* ===========================
   レスポンシブ
=========================== */
@media (max-width: 480px) {
  .start-content { padding: 30px 16px 50px; gap: 16px; }
  .game-main     { padding: 16px 14px; gap: 16px; }
  .answer-form   { flex-direction: column; gap: 8px; }
  .btn-submit    { width: 100%; }
  .result-cards  { gap: 10px; }
  .result-card   { min-width: 90px; padding: 14px 8px; }
  .result-value  { font-size: 1.3rem; }
  .clear-content { padding: 36px 16px 50px; gap: 22px; }
}
