/* =========================================================
 * こどもにほんご — 兒童日文學習 PWA 樣式
 * 設計原則：大按鈕、粉嫩色、圓角、適合兒童手指
 * ========================================================= */

:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --pink: #ff8fab;
  --pink-soft: #ffd6e0;
  --blue: #7ec8e3;
  --blue-soft: #d6efff;
  --yellow: #ffd166;
  --green: #8fd694;
  --green-soft: #e2f7e3;
  --purple-soft: #eaddff;
  --text: #4a3f35;
  --text-soft: #8a7d6f;
  --radius: 22px;
  --shadow: 0 4px 14px rgba(120, 90, 60, 0.14);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Hiragino Sans", "Noto Sans TC", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }
.hidden { display: none !important; }

/* 手繪 SVG 插圖：跟著容器的 font-size 縮放（和 emoji 一樣的行為） */
.art { width: 1.3em; height: 1.3em; display: block; margin: 0 auto; }
.art-emoji { display: block; }
.fc-emoji .art, .speak-card .art { width: 140px; height: 140px; }
.choice-btn .art { width: 84px; height: 84px; }
.kd-emoji .art { width: 72px; height: 72px; }
.deck-emoji .art { width: 60px; height: 60px; }

/* ---------- 頂欄 ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--pink-soft);
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
}

#topbar-title {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--card);
  font-size: 1.2rem;
  box-shadow: var(--shadow);
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 30px);
}

.screen { animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ---------- 選玩家 ---------- */
.app-title {
  text-align: center;
  font-size: 2.3rem;
  margin: 40px 0 8px;
  color: var(--pink);
}
.app-title small { font-size: 1.1rem; color: var(--text-soft); font-weight: 600; }

.subtitle {
  text-align: center;
  font-size: 1.2rem;
  color: var(--text-soft);
  margin: 10px 0 24px;
}

.profile-list {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.profile-card {
  width: 200px;
  padding: 26px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform 0.12s;
}
.profile-card:active { transform: scale(0.95); }
.profile-avatar { font-size: 3.6rem; display: block; }
.profile-name { font-size: 1.5rem; font-weight: 800; margin-top: 8px; }
.profile-stars { color: var(--text-soft); font-size: 1.1rem; margin-top: 6px; }
.profile-edit { margin-top: 10px; font-size: 0.95rem; color: var(--blue); font-weight: 700; }
.profile-rename {
  width: 90%;
  font-size: 1.3rem;
  text-align: center;
  border: 2px solid var(--pink-soft);
  border-radius: 12px;
  padding: 6px;
  margin-top: 8px;
}

/* ---------- 主選單 ---------- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 10px;
}

.menu-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s;
}
.menu-card:active { transform: scale(0.94); }
.menu-card:nth-child(1) { background: var(--blue-soft); }
.menu-card:nth-child(2) { background: var(--pink-soft); }
.menu-card:nth-child(3) { background: var(--green-soft); }
.menu-card:nth-child(4) { background: var(--purple-soft); }
.menu-card:nth-child(5) { background: #fff0cc; }
.menu-card:nth-child(6) { background: #ffe3d6; }

.menu-emoji { font-size: 2.6rem; }
.menu-name { font-size: 1.35rem; font-weight: 800; }
.menu-sub { font-size: 0.95rem; color: var(--text-soft); }

.home-stats {
  margin-top: 24px;
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-soft);
  line-height: 1.8;
}

/* ---------- 50 音表 ---------- */
.tabs { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.tab {
  padding: 10px 26px;
  border-radius: 999px;
  background: var(--card);
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  line-height: 1.3;
}
.tab small { font-size: 0.8rem; color: var(--text-soft); }
.tab.active { background: var(--pink); color: white; }
.tab.active small { color: #ffe9f0; }

.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.kana-cell {
  aspect-ratio: 1;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.kana-cell:active { transform: scale(0.9); }
.kana-cell.empty { background: transparent; box-shadow: none; pointer-events: none; }
.kana-char { font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 700; }
.kana-romaji { font-size: 0.8rem; color: var(--text-soft); }
.kana-cell.learned { outline: 3px solid var(--yellow); }

.kana-detail {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  width: min(92vw, 460px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(120, 90, 60, 0.3);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 20;
}
.kd-emoji { font-size: 3rem; }
.kd-word { font-size: 1.6rem; font-weight: 800; }
.kd-sub { color: var(--text-soft); font-size: 1rem; }
.kd-zh { color: var(--text-soft); font-size: 1.05rem; }
.kd-play { margin-left: auto; }

/* ---------- 平片假名說明頁 ---------- */
#kanainfo-content { display: grid; gap: 14px; max-width: 520px; margin: 0 auto; }
.info-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.info-card.center { text-align: center; }
.info-card h3 { font-size: 1.2rem; margin-bottom: 8px; }
.info-card p { font-size: 1.05rem; line-height: 1.7; color: var(--text); }
.info-card .big-btn { margin-top: 14px; }
.info-big { font-size: 2.6rem; font-weight: 800; color: var(--pink); margin-bottom: 8px; }
.info-word {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--bg);
  border-radius: 16px;
  padding: 10px 14px;
  margin-top: 10px;
  text-align: left;
  transition: transform 0.12s;
}
.info-word:active { transform: scale(0.97); }
.info-word .art { width: 52px; height: 52px; margin: 0; }
.info-word b { font-size: 1.3rem; display: block; }
.info-word small { color: var(--text-soft); font-size: 0.92rem; }
.info-word .iw-play { margin-left: auto; font-size: 1.3rem; }

/* ---------- 單字主題選單 ---------- */
.deck-list { display: grid; gap: 14px; }
.deck-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  text-align: left;
  transition: transform 0.12s;
}
.deck-card:active { transform: scale(0.97); }
.deck-emoji { font-size: 2.6rem; }
.deck-name { font-size: 1.3rem; font-weight: 800; }
.deck-desc { color: var(--text-soft); font-size: 0.98rem; }

/* ---------- 單字卡 ---------- */
.flashcard {
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  text-align: center;
  padding: 40px 20px 26px;
  margin: 8px auto 20px;
  max-width: 460px;
  transition: transform 0.12s;
}
.flashcard:active { transform: scale(0.97); }
.fc-emoji { font-size: 5rem; }
.fc-jp { font-size: 2.6rem; font-weight: 800; margin-top: 10px; }
.fc-reading { font-size: 1.1rem; color: var(--text-soft); }
.fc-zh { font-size: 1.4rem; color: var(--pink); font-weight: 700; margin-top: 6px; }
.fc-tap-hint { margin-top: 16px; font-size: 0.95rem; color: var(--text-soft); }

.card-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.fc-count { font-size: 1.1rem; color: var(--text-soft); min-width: 70px; text-align: center; }

.big-btn {
  background: var(--pink);
  color: white;
  font-size: 1.2rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 14px 26px;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.big-btn:active { transform: scale(0.94); }
.big-btn.secondary { background: var(--card); color: var(--text); }

.text-btn {
  display: block;
  margin: 18px auto 0;
  font-size: 1.05rem;
  color: var(--blue);
  font-weight: 700;
  text-decoration: underline;
}

/* ---------- 測驗 ---------- */
.quiz-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 1.15rem;
  font-weight: 700;
}
.quiz-score { color: var(--pink); }

.quiz-prompt {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
  padding: 18px;
  text-align: center;
}
.qp-big { font-size: 3.2rem; font-weight: 800; }
.qp-hint { color: var(--text-soft); font-size: 1rem; }

.play-big {
  font-size: 3rem;
  background: var(--blue-soft);
  border-radius: 50%;
  width: 96px;
  height: 96px;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.play-big:active { transform: scale(0.9); }

.quiz-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.choice-btn {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 8px;
  font-size: 2.2rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s;
}
.choice-btn:active { transform: scale(0.94); }
.choice-btn small { font-size: 1rem; color: var(--text-soft); font-weight: 600; }
.choice-btn.correct { background: var(--green); color: white; }
.choice-btn.correct small { color: #f0fff0; }
.choice-btn.wrong { background: #ffb3b3; }
.choice-btn:disabled { opacity: 0.95; }

.quiz-feedback {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  min-height: 2.2rem;
  margin-top: 16px;
}

/* ---------- 跟讀模式 ---------- */
.speak-card {
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  text-align: center;
  padding: 30px 20px 22px;
  max-width: 460px;
  margin: 0 auto 16px;
}

.speak-status {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  min-height: 2rem;
  margin-bottom: 16px;
}

.speak-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 26px;
}

.round-btn {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  font-size: 2.6rem;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.round-btn:active { transform: scale(0.9); }
.round-btn.listen { background: var(--blue-soft); }
.round-btn.mic { background: var(--pink-soft); }
.round-btn.mic.recording {
  background: var(--pink);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 143, 171, 0.6); }
  50% { box-shadow: 0 0 0 18px rgba(255, 143, 171, 0); }
}

/* ---------- 結果畫面 ---------- */
.result-box {
  text-align: center;
  padding-top: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.result-stars { font-size: 3.6rem; letter-spacing: 6px; }
.result-stars .star { display: inline-block; animation: pop 0.5s ease backwards; }
.result-stars .star:nth-child(2) { animation-delay: 0.25s; }
.result-stars .star:nth-child(3) { animation-delay: 0.5s; }
@keyframes pop { from { transform: scale(0); } 60% { transform: scale(1.4); } to { transform: scale(1); } }
.result-score { font-size: 1.8rem; font-weight: 800; color: var(--pink); }
.result-msg { font-size: 1.25rem; color: var(--text-soft); }

/* ---------- 稱讚泡泡 ---------- */
.praise-pop {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--yellow);
  border-radius: 999px;
  padding: 18px 34px;
  font-size: 1.7rem;
  font-weight: 800;
  box-shadow: 0 8px 30px rgba(120, 90, 60, 0.3);
  z-index: 50;
  text-align: center;
  animation: pop 0.4s ease;
  pointer-events: none;
}
.praise-pop small { display: block; font-size: 1.05rem; color: var(--text); }

/* ---------- 50音闖關地圖 ---------- */
.stage-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; padding: 4px 2px 24px;
}
.stage-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: none; border-radius: 20px; padding: 14px 10px 12px;
  background: white; box-shadow: 0 4px 14px rgba(0,0,0,.10);
  font-family: inherit; cursor: pointer; transition: transform .08s;
}
.stage-card:active { transform: scale(0.96); }
.stage-card.locked { background: #eceff1; box-shadow: none; opacity: .65; cursor: default; }
.stage-card.done { background: linear-gradient(160deg, #fffbe6, #fff2c2); }
.stage-kana { font-size: 1.5rem; font-weight: 700; letter-spacing: 2px; }
.stage-name { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.stage-stars { font-size: 1.1rem; letter-spacing: 3px; }
.stage-next { font-size: .82rem; color: var(--text-soft); }
.quest-card { grid-column: 1 / -1; }

/* 答錯兩次之後，正確答案會發光 */
.choice-btn.hint-glow { animation: hintglow 0.9s ease-in-out infinite; }
@keyframes hintglow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, .0); }
  50%      { box-shadow: 0 0 0 8px rgba(255, 193, 7, .55); }
}
.choice-btn.wrong { opacity: .45; }
.result-stars .star.dim { opacity: .3; }
