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

:root {
  --sky:    #7dd3fc;
  --mint:   #a7f3d0;
  --lime:   #bef264;
  --yellow: #fde68a;
  --pink:   #fbcfe8;
  --white:  #ffffff;
  --navy:   #1e293b;
  --gray:   #64748b;
  --light-bg: #f0faff;

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

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

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: linear-gradient(160deg, #fff9f0 0%, #fff3e0 40%, #e8f4fd 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-circles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  /* カレンダーグリッド風の薄いライン */
  background-image:
    linear-gradient(rgba(255,183,77,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,183,77,0.08) 1px, transparent 1px);
  background-size: 48px 48px;
}

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

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

.bg-circles::after {
  width: 320px; height: 320px;
  background: #90caf9;
  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;
}

/* ===========================
   ===== スタート画面 =====
=========================== */
.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(2.2rem, 8vw, 3.2rem);
  font-weight: 800;
  color: #e65100;
  text-shadow:
    0 0 20px rgba(255, 180, 50, 0.6),
    0 3px 0 #bf360c,
    0 6px 12px rgba(0,0,0,0.12);
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.title-deco {
  font-size: 1.6rem;
  color: #f57c00;
  filter: drop-shadow(0 0 6px rgba(255, 160, 0, 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: #e65100;
  font-weight: 700;
}

/* バッジ */
.info-badges {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.info-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: default;
  user-select: none;
  pointer-events: none;
  /* ホバーアニメーションなし */
}

.badge-questions {
  background: linear-gradient(135deg, #bae6fd, #e0f2fe);
  color: #0369a1;
  border: 2px solid #7dd3fc;
  box-shadow: 0 4px 14px rgba(125, 211, 252, 0.3);
}

.badge-hint {
  background: linear-gradient(135deg, #ffe0b2, #fff3e0);
  color: #bf360c;
  border: 2px solid #ffb74d;
  box-shadow: 0 4px 14px rgba(255, 183, 77, 0.35);
}

.badge-icon {
  font-size: 1.1rem;
}

/* スタートボタン */
.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, #fb8c00, #ffa726);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 24px rgba(251, 140, 0, 0.45), 0 2px 0 #e65100 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(251, 140, 0, 0.55), 0 2px 0 #e65100 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; }
}

.btn-arrow {
  font-size: 1rem;
}

/* ===========================
   ===== ゲーム画面 =====
=========================== */
#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(255, 183, 77, 0.35);
  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, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1;
}

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

/* 状態ごとのスタイル */
.nav-btn.state-current {
  background: linear-gradient(135deg, #fb8c00, #ffa726);
  color: white;
  border-color: #e65100;
  box-shadow: 0 4px 14px rgba(251, 140, 0, 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);
  box-shadow: 0 5px 16px rgba(110, 231, 183, 0.45);
}

.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(125, 211, 252, 0.4);
  min-height: 80px;
}

/* <img> は常にこのスタイル */
.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;
}

/* JS から .is-visible を付けると表示される */
.question-image.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.question-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
}

/* 閲覧モード：答え表示 */
.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);
  animation: fadeSlideIn 0.3s ease-out;
}

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

/* ミス回数 */
.miss-count-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

.miss-stars {
  font-size: 1.1rem;
  letter-spacing: 3px;
}

.miss-text {
  font-size: 0.82rem;
  color: #ef4444;
  font-weight: 700;
}

/* 入力フォーム */
.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(125, 211, 252, 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: #ffa726;
  box-shadow: 0 0 0 4px rgba(255, 167, 38, 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, #fb8c00, #ffa726);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(251, 140, 0, 0.35);
}

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

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

/* フィードバック */
.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);
}

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

.hint-icon {
  font-size: 1rem;
}

.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;
  position: relative;
  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: 8px;
}

/* クリア画面上部画像 */
.clear-top-image {
  width: 220px;
  height: 220px;
  object-fit: cover;
  border-radius: 16px;
  border: 4px solid #ffb74d;
  box-shadow: 0 6px 24px rgba(251, 140, 0, 0.3);
  animation: trophyBounce 0.8s cubic-bezier(0.2, 0.6, 0.3, 1.5) both;
}

.clear-trophy {
  font-size: 4rem;
  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: #e65100;
  text-shadow:
    0 0 20px rgba(255, 180, 50, 0.6),
    0 3px 0 #bf360c,
    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;
}

/* 結果カード */
.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(125, 211, 252, 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);
  letter-spacing: 0.05em;
}

.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);
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
}

.x-icon {
  flex-shrink: 0;
}

.btn-retry {
  width: 100%;
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font);
  color: #bf360c;
  background: rgba(255,255,255,0.82);
  border: 2px solid #ffb74d;
  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(255, 183, 77, 0.35);
}

/* ===========================
   レスポンシブ
=========================== */
@media (max-width: 480px) {
  .start-content {
    padding: 30px 16px 50px;
    gap: 16px;
  }

  .chara-wrap {
    width: 180px;
    height: 230px;
  }

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