/* ===== カラーパレット & フォント（math-cards-app と共通のテーマ） ===== */
:root {
  /* メインカラー：ピンク〜マゼンタ */
  --color-primary:        #ff4a99;
  --color-primary-light:  #ffb3d1;
  --color-primary-dark:   #c8267a;

  /* サブカラー：パステル */
  --color-lavender: #c8a4ff;
  --color-skyblue:  #a0d8ff;
  --color-mint:     #b8f2d8;
  --color-lemon:    #fff5a0;

  /* アクセント */
  --color-gold:   #ffd700;
  --color-green:  #38c172;
  --color-green-dark: #2aa75f;
  --color-red:    #ff6b6b;

  /* テキスト */
  --color-text:        #4a3568;  /* 深い紫 */
  --color-text-light:  #8a7aa8;

  /* グラデーション */
  --gradient-bg: linear-gradient(180deg, #ffe4f1 0%, #f3d9ff 50%, #d4f1ff 100%);

  /* フォント */
  --font-display: 'Mochiy Pop One', 'M PLUS Rounded 1c', "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  --font-body:    'M PLUS Rounded 1c', "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100vh;
  height: 100dvh;
}
body {
  height: 100%;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
  background: var(--gradient-bg);
  background-attachment: fixed;
}

.hidden { display: none !important; }

/* ===== 背景キラキラ装飾 ===== */
.bg-sparkles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.sparkle {
  position: absolute;
  pointer-events: none;
  line-height: 1;
  animation: twinkle 4s ease-in-out infinite;
  will-change: transform, opacity;
}
.sparkle.circle { border-radius: 50%; }
.sparkle.circle.white { background: #ffffff; box-shadow: 0 0 8px 2px rgba(255, 255, 255, 0.85); }
.sparkle.circle.gold  { background: #fff2a8; box-shadow: 0 0 8px 2px rgba(255, 215, 100, 0.8); }
.sparkle.circle.pink  { background: #ffd6e8; box-shadow: 0 0 8px 2px rgba(255, 180, 220, 0.8); }
.sparkle.star {
  display: inline-block;
  font-weight: normal;
  text-align: center;
}
.sparkle.star.white { color: #ffffff; text-shadow: 0 0 6px rgba(255, 255, 255, 0.95), 0 0 10px rgba(255, 255, 255, 0.6); }
.sparkle.star.gold  { color: #ffe680; text-shadow: 0 0 6px rgba(255, 215, 100, 0.95), 0 0 10px rgba(255, 215, 100, 0.6); }
.sparkle.star.pink  { color: #ffc6dc; text-shadow: 0 0 6px rgba(255, 180, 220, 0.95), 0 0 10px rgba(255, 180, 220, 0.6); }

@keyframes twinkle {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50%      { opacity: 1;   transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .sparkle { animation: none; opacity: 0.7; }
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  max-width: 600px;
  margin: 0 auto;
}

/* ===== Screen ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  padding: 20px;
  flex-direction: column;
  overflow: hidden;
}
.screen.active {
  display: flex;
  animation: screen-in 0.25s ease-out;
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.screen-header h2 {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: clamp(1.05rem, 4.6vw, 1.5rem);
  flex: 1;
  min-width: 0;
  text-align: center;
  padding-right: 74px;
  color: var(--color-primary-dark);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.9), 0 2px 4px rgba(200, 80, 160, 0.15);
  white-space: nowrap;
  word-break: keep-all;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* ===== Buttons ===== */
.btn {
  display: block;
  width: 100%;
  padding: 16px 18px;
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.3rem;
  border: none;
  border-radius: 22px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: translateY(3px); }

.btn-primary {
  background: linear-gradient(180deg, #ff7ab6 0%, #ff4a99 60%, #e6338a 100%);
  color: #fff;
  padding: 20px 18px;
  font-size: 1.5rem;
  box-shadow:
    0 5px 0 #b01f6b,
    0 10px 22px rgba(200, 40, 120, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  text-shadow: 0 2px 3px rgba(150, 30, 90, 0.45);
}
.btn-primary::after {
  content: '';
  position: absolute;
  top: 10%;
  left: 12%;
  width: 45%;
  height: 36%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 100%);
  border-radius: 50%;
  pointer-events: none;
  filter: blur(2px);
}
.btn-primary:active {
  box-shadow:
    0 1px 0 #b01f6b,
    0 4px 10px rgba(200, 40, 120, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.btn-sub {
  background: linear-gradient(180deg, #ffffff 0%, #ffeaf3 100%);
  color: var(--color-primary-dark);
  border: 3px solid var(--color-primary-light);
  padding: 14px 18px;
  font-size: 1.15rem;
  box-shadow:
    0 3px 0 rgba(255, 74, 153, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.btn-sub:active {
  box-shadow:
    0 1px 0 rgba(255, 74, 153, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.btn-back {
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid var(--color-primary-light);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-primary-dark);
  font-weight: 700;
  cursor: pointer;
  padding: 6px 12px;
}
.btn-back:active { transform: scale(0.95); background: rgba(255, 234, 243, 0.9); }

/* ===== ホーム画面 ===== */
#screen-home {
  justify-content: center;
  align-items: center;
  text-align: center;
}
.title {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 3.2rem;
  line-height: 1.05;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #ffb3d9 0%, #ff4a99 45%, #c8267a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(255, 255, 255, 0.95)) drop-shadow(0 6px 14px rgba(200, 38, 122, 0.35));
  position: relative;
  animation: title-bob 3.8s ease-in-out infinite;
}
@keyframes title-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.title::before,
.title::after {
  position: absolute;
  font-size: 1.8rem;
  color: var(--color-gold);
  -webkit-text-fill-color: var(--color-gold);
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.85));
  animation: sparkle-spin 4s linear infinite;
}
.title::before { content: '✨'; top: -6px; left: -22px; }
.title::after  { content: '✨'; bottom: -4px; right: -22px; animation-delay: -2s; animation-direction: reverse; }
@keyframes sparkle-spin {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}
.home-sub {
  font-size: 1rem;
  color: var(--color-text-light);
  margin-bottom: 40px;
}
.menu {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== レベル選択 ===== */
.level-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 4px 2px 8px;
}
.level-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 22px;
  padding: 16px;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.5);
  box-shadow:
    0 6px 16px rgba(200, 80, 160, 0.18),
    inset 0 0 24px rgba(255, 255, 255, 0.28);
  transition: transform 0.1s, box-shadow 0.15s;
}
.level-card:active:not(:disabled) {
  transform: scale(0.98);
  box-shadow: 0 3px 8px rgba(200, 80, 160, 0.2);
}
.level-badge {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: #fff;
  background: linear-gradient(160deg, #ff7ab6, #ff4a99);
  box-shadow: 0 4px 0 rgba(200, 40, 120, 0.4);
}
.level-text { display: flex; flex-direction: column; }
.level-title { font-size: 1.4rem; font-weight: 900; color: var(--color-text); }
.level-desc { font-size: 0.95rem; color: var(--color-text-light); }
.level-lock { margin-left: auto; font-size: 1.4rem; }
.level-locked {
  opacity: 0.55;
  filter: grayscale(0.5);
  cursor: not-allowed;
}
.level-locked .level-badge {
  background: linear-gradient(160deg, #c9c3da, #aaa2c8);
  box-shadow: none;
}

/* ===== モード選択 ===== */
.mode-intro {
  text-align: center;
  color: var(--color-text-light);
  margin-bottom: 16px;
}
.mode-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 4px 2px 8px;
}
.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 22px;
  padding: 22px 16px;
  cursor: pointer;
  color: #fff;
  box-shadow:
    0 6px 16px rgba(200, 80, 160, 0.22),
    inset 0 0 24px rgba(255, 255, 255, 0.18);
  transition: transform 0.1s, box-shadow 0.15s;
}
.mode-card:active {
  transform: scale(0.98);
  box-shadow: 0 3px 8px rgba(200, 80, 160, 0.2);
}
.mode-practice { background: linear-gradient(160deg, #7fd1ff, #4aa8f5); }
.mode-challenge { background: linear-gradient(160deg, #ffb14a, #ff8a3d); }
.mode-card-emoji { font-size: 2.2rem; }
.mode-card-title { font-family: var(--font-display); font-weight: normal; font-size: 1.6rem; }
.mode-card-desc { font-size: 0.95rem; opacity: 0.97; }
.mode-card-best {
  margin-top: 8px;
  font-size: 0.95rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.28);
  padding: 4px 14px;
  border-radius: 999px;
}

/* ===== プレイ画面 ===== */
#screen-play { justify-content: flex-start; }
.play-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.btn-quit {
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid var(--color-primary-light);
  border-radius: 999px;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--color-primary-dark);
  cursor: pointer;
  padding: 8px 16px;
}
.btn-quit:active { transform: scale(0.95); }
.play-progress {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 1.5rem;
  color: var(--color-text);
}
.play-progress.timer-low { color: var(--color-red); }
.play-score {
  font-weight: 900;
  font-size: 1.2rem;
  color: var(--color-text);
  background: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(200, 80, 160, 0.18);
}

.speech-bubble {
  align-self: center;
  background: #fff;
  color: var(--color-text);
  font-size: 1.15rem;
  font-weight: 800;
  padding: 12px 20px;
  border-radius: 18px;
  box-shadow: 0 4px 0 rgba(200, 80, 160, 0.15);
  text-align: center;
  margin-bottom: 14px;
  min-height: 24px;
}

.staff-card {
  background: #fff;
  border-radius: 24px;
  box-shadow:
    0 8px 0 rgba(200, 80, 160, 0.16),
    0 14px 26px rgba(200, 80, 160, 0.2);
  padding: 18px 12px;
  display: grid;
  place-items: center;
  transition: box-shadow 0.15s ease;
}
.staff-card.card-correct { box-shadow: 0 0 0 4px var(--color-green), 0 8px 0 rgba(200, 80, 160, 0.16); }
.staff-card.card-wrong   { box-shadow: 0 0 0 4px var(--color-red), 0 8px 0 rgba(200, 80, 160, 0.16); }
.staff { width: 100%; max-width: 360px; height: auto; }

/* 回答ボタン */
.answer-pad {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
.ans {
  padding: 16px 0;
  font-family: var(--font-display);
  font-weight: normal;
  font-size: clamp(1rem, 4.6vw, 1.4rem);
  color: var(--color-primary-dark);
  background: #fff;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(255, 74, 153, 0.3);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.ans:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(255, 74, 153, 0.3);
}
.ans-correct {
  color: #fff;
  background: linear-gradient(160deg, var(--color-green), var(--color-green-dark));
  box-shadow: 0 4px 0 rgba(42, 167, 95, 0.4);
  animation: pop 0.3s ease;
}
.ans-wrong {
  color: #fff;
  background: linear-gradient(160deg, #ff8a8a, var(--color-red));
  box-shadow: 0 4px 0 rgba(220, 60, 60, 0.4);
}
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* せまい画面では 4列×2段にして押しやすく保つ */
@media (max-width: 480px) {
  .answer-pad {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  .ans { padding: 18px 0; font-size: 1.4rem; }
}

/* ===== 結果画面 ===== */
#screen-result {
  justify-content: center;
  align-items: center;
}
.result-title {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  color: var(--color-primary-dark);
  text-align: center;
  margin-bottom: 18px;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
}
.result-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 24px;
  box-shadow:
    0 8px 0 rgba(200, 80, 160, 0.16),
    0 14px 26px rgba(200, 80, 160, 0.2);
  padding: 24px 22px;
  text-align: center;
  margin-bottom: 22px;
}
.result-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.result-label {
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-text-light);
}
.result-value {
  font-family: var(--font-display);
  font-weight: normal;
  font-size: 3.4rem;
  color: var(--color-text);
  line-height: 1.1;
}
.result-unit {
  font-size: 1.3rem;
  margin-left: 6px;
  color: var(--color-text-light);
}
.result-best {
  margin-top: 14px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--color-text);
}
.result-best-new { color: var(--color-primary-dark); }
.result-actions {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
