/* じゅけんクエスト — iPhone縦持ち特化スタイル */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", sans-serif;
  background: #87ceeb;
  color: #333;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== 画面切り替え ===== */
.screen {
  display: none; position: fixed; inset: 0;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; animation: screenIn 0.35s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ===== タイトル ===== */
#screen-title { background: linear-gradient(180deg, #6ec6ff 0%, #b3e5fc 55%, #ffe9a8 100%); align-items: center; justify-content: center; }
.title-sky { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.title-sun { position: absolute; top: 8%; right: 10%; font-size: 56px; animation: sunSpin 24s linear infinite; }
@keyframes sunSpin { to { transform: rotate(360deg); } }
.cloud { position: absolute; font-size: 44px; opacity: 0.9; animation: cloudMove 30s linear infinite; }
.cloud.c1 { top: 12%; animation-duration: 36s; }
.cloud.c2 { top: 24%; animation-duration: 28s; animation-delay: -12s; }
.cloud.c3 { top: 6%; animation-duration: 44s; animation-delay: -24s; }
@keyframes cloudMove { from { left: -15%; } to { left: 110%; } }
.title-body { position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px; }
.title-main {
  font-size: 3.2rem; font-weight: 900; text-align: center; line-height: 1.15;
  color: #fff; -webkit-text-stroke: 2px #ff8f00;
  text-shadow: 0 4px 0 #e65100, 0 8px 18px rgba(0,0,0,0.25);
  animation: titleBounce 2.4s ease-in-out infinite;
}
@keyframes titleBounce { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
.title-sub { font-size: 1rem; font-weight: 700; color: #5d4037; text-align: center; margin-top: 6px; }
.title-island { font-size: 90px; animation: islandFloat 3.5s ease-in-out infinite; }
@keyframes islandFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.title-friends { display: flex; gap: 6px; font-size: 26px; min-height: 34px; flex-wrap: wrap; justify-content: center; max-width: 320px; }

/* ===== 共通ボタン ===== */
.big-btn {
  border: none; border-radius: 999px; cursor: pointer;
  padding: 18px 36px; font-size: 1.25rem; font-weight: 900; color: #fff;
  background: linear-gradient(180deg, #ffb74d, #ff9800);
  box-shadow: 0 6px 0 #e65100, 0 10px 20px rgba(0,0,0,0.2);
  transition: transform 0.1s;
  font-family: inherit;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #e65100; }
.back-btn {
  border: none; background: rgba(255,255,255,0.9); border-radius: 50%;
  width: 44px; height: 44px; font-size: 1.3rem; font-weight: 900; color: #555;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); cursor: pointer; flex-shrink: 0;
}
.footer-btn {
  flex: 1; border: none; border-radius: 16px; padding: 14px 8px;
  font-size: 1rem; font-weight: 800; color: #5d4037; font-family: inherit;
  background: rgba(255,255,255,0.92); box-shadow: 0 3px 10px rgba(0,0,0,0.12); cursor: pointer;
}

/* ===== マップ ===== */
#screen-map { background: linear-gradient(180deg, #4fc3f7 0%, #81d4fa 30%, #a5d6a7 100%); }
.map-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; }
.map-title { font-size: 1.4rem; font-weight: 900; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.25); }
.map-status { display: flex; gap: 10px; font-weight: 900; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.3); font-size: 1.05rem; }
.map-areas { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 16px; }
.area-card {
  display: flex; align-items: center; gap: 14px;
  background: rgba(255,255,255,0.95); border-radius: 22px; padding: 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15); cursor: pointer;
  border: 3px solid transparent; transition: transform 0.12s;
  position: relative; overflow: hidden;
}
.area-card:active { transform: scale(0.97); }
.area-card .area-emoji { font-size: 46px; flex-shrink: 0; }
.area-card .area-info { flex: 1; min-width: 0; }
.area-card .area-name { font-size: 1.15rem; font-weight: 900; }
.area-card .area-desc { font-size: 0.78rem; color: #888; margin-top: 2px; }
.area-card .area-stars { font-size: 0.85rem; margin-top: 4px; color: #ff9800; font-weight: 800; }
.area-card.locked { filter: grayscale(0.9); opacity: 0.7; }
.area-card.locked::after {
  content: "🔒"; position: absolute; right: 16px; font-size: 28px;
}
.map-footer { display: flex; gap: 12px; padding: 4px 16px calc(16px + env(safe-area-inset-bottom)); margin-top: auto; }

/* ===== ステージ選択 ===== */
#screen-stage { background: linear-gradient(180deg, #b39ddb, #d1c4e9 60%, #f3e5f5); }
.stage-header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.stage-area-name { font-size: 1.25rem; font-weight: 900; color: #4a306d; }
.stage-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 10px 18px 24px; }
.stage-card {
  background: #fff; border-radius: 20px; padding: 18px 10px; text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.13); cursor: pointer; transition: transform 0.12s;
  border: 3px solid transparent;
}
.stage-card:active { transform: scale(0.95); }
.stage-card.locked { filter: grayscale(1); opacity: 0.55; }
.stage-card .stage-num { font-size: 1.9rem; font-weight: 900; color: #7e57c2; }
.stage-card .stage-label { font-size: 0.8rem; color: #999; font-weight: 700; }
.stage-card .stage-stars { font-size: 1rem; margin-top: 6px; letter-spacing: 2px; }
.stage-card.boss { grid-column: span 2; background: linear-gradient(135deg, #ffe082, #ffcc80); border-color: #ffb300; }
.stage-card.boss .stage-num { color: #e65100; font-size: 1.5rem; }

/* ===== プレイ ===== */
#screen-play, #screen-story { background: linear-gradient(180deg, #fffde7, #fff8e1); }
.play-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.play-progress { flex: 1; text-align: center; font-weight: 900; color: #795548; font-size: 1.05rem; }
.play-hearts { font-size: 1.05rem; min-width: 70px; text-align: right; }
.play-area { display: flex; flex-direction: column; padding: 6px 16px 28px; gap: 14px; flex: 1; }

.q-prompt {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 18px; padding: 14px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.1);
  font-size: 1.12rem; font-weight: 900; color: #444;
}
.q-prompt .speak-again { border: none; background: #e3f2fd; border-radius: 50%; width: 42px; height: 42px; font-size: 1.2rem; cursor: pointer; flex-shrink: 0; }
.q-visual {
  background: #fff; border-radius: 18px; padding: 16px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.1);
  text-align: center; font-size: 2rem; line-height: 1.5; letter-spacing: 4px;
  min-height: 70px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
}
.q-visual svg { max-width: 100%; }
.q-visual .vs-row { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; flex-wrap: wrap; }
.q-visual .vs-group { background: #f5f5f5; border-radius: 14px; padding: 10px; font-size: 1.7rem; letter-spacing: 2px; max-width: 45%; line-height: 1.4; }
.q-visual .vs-label { display: block; font-size: 0.85rem; letter-spacing: 0; color: #888; font-weight: 800; margin-bottom: 4px; }

.q-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: auto; }
.q-option {
  border: 3px solid #e0e0e0; border-radius: 18px; background: #fff;
  min-height: 76px; font-size: 1.6rem; font-weight: 900; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 10px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08); transition: transform 0.1s;
  font-family: inherit; line-height: 1.3;
}
.q-option:active { transform: scale(0.95); }
.q-option.correct { border-color: #4caf50; background: #e8f5e9; animation: popCorrect 0.45s ease; }
.q-option.wrong { border-color: #ef5350; background: #ffebee; animation: shakeWrong 0.45s ease; }
.q-option svg { pointer-events: none; }
@keyframes popCorrect { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes shakeWrong { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

/* ===== お話の記憶 ===== */
.story-area { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 20px; flex: 1; justify-content: center; }
.story-card {
  background: #fff; border-radius: 24px; padding: 26px 22px; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12); max-width: 340px; width: 100%;
}
.story-emoji { font-size: 72px; animation: storyBob 2.6s ease-in-out infinite; }
@keyframes storyBob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }
.story-title { font-size: 1.3rem; font-weight: 900; margin-top: 10px; color: #5d4037; }
.story-note { font-size: 0.9rem; color: #999; margin-top: 8px; font-weight: 700; }
.story-wave { display: flex; gap: 5px; justify-content: center; margin-top: 16px; height: 28px; align-items: flex-end; }
.story-wave span { width: 7px; border-radius: 4px; background: #4fc3f7; animation: wave 1s ease-in-out infinite; }
.story-wave span:nth-child(2) { animation-delay: 0.15s; } .story-wave span:nth-child(3) { animation-delay: 0.3s; }
.story-wave span:nth-child(4) { animation-delay: 0.45s; } .story-wave span:nth-child(5) { animation-delay: 0.6s; }
@keyframes wave { 0%,100% { height: 8px; } 50% { height: 26px; } }

/* ===== 結果 ===== */
#screen-result { background: linear-gradient(180deg, #fff59d, #ffe082); align-items: center; justify-content: center; }
.result-area { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px; text-align: center; }
.result-title { font-size: 2.2rem; font-weight: 900; color: #e65100; text-shadow: 0 3px 0 rgba(255,255,255,0.7); }
.result-stars { font-size: 3rem; letter-spacing: 6px; }
.result-stars .dim { opacity: 0.25; }
.result-stars span { display: inline-block; animation: starPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.result-stars span:nth-child(2) { animation-delay: 0.25s; }
.result-stars span:nth-child(3) { animation-delay: 0.5s; }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.result-detail { font-size: 1.05rem; font-weight: 800; color: #6d4c41; }
.result-friend {
  background: #fff; border-radius: 24px; padding: 18px 26px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15); animation: friendIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes friendIn { from { transform: scale(0); } to { transform: scale(1); } }
.result-friend .friend-emoji { font-size: 64px; }
.result-friend .friend-name { font-weight: 900; color: #5d4037; margin-top: 4px; }
.result-friend .friend-label { font-size: 0.8rem; color: #ff9800; font-weight: 900; }
.result-btns { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }

/* ===== なかま図鑑 ===== */
#screen-friends { background: linear-gradient(180deg, #80deea, #b2ebf2 60%, #e0f7fa); }
.friends-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 10px 16px 24px; }
.friend-card {
  background: #fff; border-radius: 18px; padding: 14px 6px; text-align: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}
.friend-card .f-emoji { font-size: 40px; }
.friend-card .f-name { font-size: 0.72rem; font-weight: 800; color: #555; margin-top: 4px; }
.friend-card.unknown { opacity: 0.5; }
.friend-card.unknown .f-emoji { filter: brightness(0); opacity: 0.35; }

/* ===== 親ダッシュボード ===== */
#screen-parent { background: #eceff1; }
.parent-area { padding: 10px 18px 30px; display: flex; flex-direction: column; gap: 14px; }
.parent-card { background: #fff; border-radius: 16px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.parent-card h3 { font-size: 1rem; color: #37474f; margin-bottom: 10px; }
.stat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.85rem; }
.stat-row .stat-name { width: 110px; font-weight: 700; color: #546e7a; flex-shrink: 0; }
.stat-row .stat-bar { flex: 1; height: 14px; background: #eceff1; border-radius: 7px; overflow: hidden; }
.stat-row .stat-fill { height: 100%; border-radius: 7px; background: linear-gradient(90deg, #66bb6a, #43a047); }
.stat-row .stat-fill.low { background: linear-gradient(90deg, #ef9a9a, #ef5350); }
.stat-row .stat-pct { width: 76px; text-align: right; font-weight: 800; color: #37474f; flex-shrink: 0; }
.parent-note { font-size: 0.78rem; color: #90a4ae; line-height: 1.6; }
.parent-gate { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px 20px; }
.parent-gate input {
  font-size: 1.6rem; width: 120px; text-align: center; padding: 10px;
  border: 2px solid #b0bec5; border-radius: 12px; font-family: inherit;
}

/* ===== 共通演出 ===== */
.toast {
  position: fixed; top: 16%; left: 50%; transform: translateX(-50%) scale(0.8);
  background: rgba(255,255,255,0.97); border-radius: 999px; padding: 12px 28px;
  font-size: 1.3rem; font-weight: 900; color: #ff6f00;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2); opacity: 0; pointer-events: none;
  transition: all 0.25s; z-index: 500; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) scale(1); }
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 600; overflow: hidden; }
.confetti-bit { position: absolute; top: -20px; border-radius: 3px; animation: confettiDrop linear forwards; }
@keyframes confettiDrop { to { transform: translateY(110vh) rotate(680deg); } }
.flash-layer {
  position: fixed; inset: 0; z-index: 550; pointer-events: none;
  background: radial-gradient(circle, rgba(255,238,140,0.6), rgba(255,255,255,0) 70%);
  animation: flashOut 0.5s ease-out forwards;
}
@keyframes flashOut { to { opacity: 0; } }
.spark {
  position: fixed; z-index: 650; pointer-events: none;
  animation: sparkFly 0.9s ease-out forwards;
}
@keyframes sparkFly {
  from { transform: translate(0,0) scale(0.5); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(1.4) rotate(60deg); opacity: 0; }
}
.mute-btn {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 400;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.9); font-size: 1.15rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ===== 大型拡張: 記憶フェーズ / デイリー / むげんの とう ===== */
.memorize-visual { min-height: 150px; }
.memorize-timer { height: 12px; background: #eee; border-radius: 6px; overflow: hidden; }
.memorize-bar {
  height: 100%; border-radius: 6px; width: 100%;
  background: linear-gradient(90deg, #66bb6a, #ffca28, #ef5350);
  animation: memShrink linear forwards;
  transform-origin: left;
}
@keyframes memShrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.memorize-count { text-align: center; font-size: 2rem; font-weight: 900; color: #ff9800; }

.daily-card { border-color: #ffca28 !important; background: linear-gradient(135deg, #fff8e1, #fffde7); }
.daily-card.done { filter: saturate(0.6); opacity: 0.85; }
.endless-card { border-color: #7e57c2 !important; background: linear-gradient(135deg, #ede7f6, #f3e5f5); }

.big-btn.btn-gray { font-size: 1rem; padding: 14px 22px; background: linear-gradient(180deg, #90a4ae, #78909c); box-shadow: 0 6px 0 #546e7a; }
.big-btn.btn-green { font-size: 1rem; padding: 14px 22px; background: linear-gradient(180deg, #81c784, #4caf50); box-shadow: 0 6px 0 #2e7d32; }
.big-btn.btn-sm { font-size: 1rem; padding: 14px 22px; }
