:root {
  --brand: #a15c2b;
  --brand-light: #fdf6ec;
  --ok: #2e8b57;
  --bad: #c0392b;
  --text: #1a1a1a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--brand-light);
  color: var(--text);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hero-band {
  padding: 14px 12px 10px;
  text-align: center;
  overflow: hidden;
}
.hero-title {
  position: relative;
  z-index: 2;
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 3px rgba(0,0,0,0.35);
}
.hero-title span { font-weight: 400; opacity: 0.9; font-size: 15px; }
.hero-title .hero-pinyin { display: inline-block; font-size: 11px; opacity: 0.8; margin-left: 2px; }

.stage-map-wrap {
  background: #175a70;
  padding: 10px 0 14px;
}
.stage-map {
  display: flex;
  gap: 10px;
  padding: 4px 14px;
  overflow-x: auto;
}
.stage-node {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 13px;
  font-weight: 700;
  background: #2a8aa8;
  color: #cfeaf3;
  border: 3px solid #114b5f;
  position: relative;
}
.stage-node .stars-mini { font-size: 8px; letter-spacing: -1px; }
.stage-node.done {
  background: linear-gradient(180deg, #ffd873 0%, #e8a63d 100%);
  color: #5a3800;
  border-color: #a86a1f;
  cursor: pointer;
}
.stage-node.locked { opacity: 0.55; }
.stage-node.selected { outline: 3px solid #fff; outline-offset: 2px; }

.modes {
  display: flex;
  gap: 8px;
  padding: 12px 12px 4px;
  overflow-x: auto;
}
.mode-tab {
  flex: 1;
  min-width: 90px;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}
.mode-tab small { display: block; opacity: 0.85; font-weight: 400; margin-top: 2px; }
.mode-tab .pinyin-tiny { font-size: 10px; opacity: 0.7; }

/* 中文 UI 文字底下的羅馬拼音小字 */
.ui-pinyin {
  display: block;
  font-size: 0.65em;
  font-weight: 400;
  color: #999;
  margin-top: 2px;
}
.feedback .ui-pinyin, .result-tier-text .ui-pinyin { color: inherit; opacity: 0.75; }
.xw-wood-btn .ui-pinyin { color: #fff8ec; opacity: 0.85; }
.ui-pinyin-inline {
  display: inline;
  font-size: 0.8em;
  font-weight: 400;
  color: #999;
  margin: 0 3px;
}

main { padding: 12px 16px 40px; max-width: 480px; margin: 0 auto; }

.progress-wrap { margin-bottom: 14px; }
.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: #eee0cf;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width 0.25s ease;
}
.progress-label { font-size: 12px; color: #888; margin-top: 6px; text-align: right; }

.card {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 24px 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.mascot-corner {
  position: absolute;
  top: -18px;
  right: 8px;
  height: 64px;
  width: auto;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15));
}

.prompt {
  font-size: 30px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 22px;
  min-height: 44px;
}
.prompt .sub { display: block; font-size: 15px; color: #888; font-weight: 400; margin-top: 6px; }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.choice-btn {
  padding: 14px 8px;
  font-size: 18px;
  border: 2px solid #eadfce;
  border-radius: 12px;
  background: #fffdfa;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  line-height: 1.2;
}
.choice-btn:active { transform: scale(0.98); }
.choice-btn.correct { border-color: var(--ok); background: #eaf7ef; color: var(--ok); }
.choice-btn.wrong { border-color: var(--bad); background: #fbeceb; color: var(--bad); }
.choice-hanzi { font-size: 18px; font-weight: 700; }
.choice-pinyin { font-size: 13px; font-weight: 400; color: var(--brand); }
.choice-btn.correct .choice-pinyin { color: var(--ok); }
.choice-btn.wrong .choice-pinyin { color: var(--bad); }
.choice-english { font-size: 11px; font-weight: 400; color: #888; }

.writing-form { display: flex; gap: 8px; }
.writing-form input {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 2px solid #eadfce;
  border-radius: 10px;
}
.writing-form button {
  padding: 12px 18px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
}

.speak-btn {
  display: block;
  margin: 0 auto 18px;
  background: var(--xw-wave-blue);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 22px;
}

.feedback {
  margin-top: 16px;
  min-height: 24px;
  text-align: center;
  font-size: 14px;
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

/* 倒數計時 */
.timer-wrap {
  position: relative;
  margin-top: 14px;
  padding-bottom: 4px;
}
.timer-track {
  height: 6px;
  border-radius: 3px;
  background: #eee0cf;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--xw-wave-blue);
  transform-origin: right center;
  transition: width 1s linear, background-color 0.3s ease;
}
.timer-fill.timer-warn { background: #e0a020; }
.timer-fill.timer-danger { background: var(--bad); }
.timer-num {
  text-align: center;
  font-size: 13px;
  color: #888;
  margin-top: 4px;
  font-weight: 700;
}
.timer-hourglass {
  position: absolute;
  right: 0;
  bottom: -2px;
  font-size: 18px;
  opacity: 0;
}
.timer-hourglass.timer-warn {
  opacity: 1;
  animation: hourglass-shake 0.5s ease-in-out infinite;
}
@keyframes hourglass-shake {
  0%, 100% { transform: rotate(-12deg); filter: brightness(1); }
  50% { transform: rotate(12deg); filter: brightness(1.6); }
}
.card.timer-danger-card {
  animation: card-flash-red 0.5s ease-in-out infinite;
}
@keyframes card-flash-red {
  0%, 100% { box-shadow: 0 2px 10px rgba(0,0,0,0.05); border: 2px solid transparent; }
  50% { box-shadow: 0 0 0 3px rgba(192,57,43,0.7); border: 2px solid var(--bad); }
}

/* 連勝／連敗 進度條特效 */
.progress-fill.streak-fire {
  background: linear-gradient(90deg, #ff8a00, #ff3d00, #ffcf00);
  background-size: 200% 100%;
  animation: fire-flow 0.6s linear infinite;
  box-shadow: 0 0 8px rgba(255, 100, 0, 0.7);
}
.progress-fill.streak-ice {
  background: linear-gradient(90deg, #8fd8ff, #dff6ff, #6fc7f0);
  background-size: 200% 100%;
  animation: ice-shimmer 1.2s linear infinite;
  box-shadow: 0 0 8px rgba(120, 200, 255, 0.7);
}
@keyframes fire-flow {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}
@keyframes ice-shimmer {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

.mascot-result-wrap {
  position: relative;
  width: 120px;
  height: 110px;
  margin: 0 auto 8px;
}
.mascot-result {
  display: block;
  height: 100px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}
.mascot-cape {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 70px;
  height: 60px;
  transform: translateX(-50%);
  background: linear-gradient(160deg, #e0393f 0%, #a3151b 100%);
  clip-path: polygon(50% 0%, 90% 15%, 100% 100%, 0% 100%, 10% 15%);
  z-index: 1;
  opacity: 0;
}
.stars {
  text-align: center;
  font-size: 34px;
  letter-spacing: 6px;
  margin: 4px 0;
}
.score-text { font-size: 20px; text-align: center; }
.result-tier-text { text-align: center; font-size: 16px; font-weight: 700; color: var(--brand); margin: 2px 0 0; }
#resultCard h2 { text-align: center; }
.result-subtitle { text-align: center; font-size: 13px; color: #888; margin: 0 0 6px; }

/* 全對：超人披風 轉圈飛起再返回 */
.mascot-result-wrap.super-win .mascot-cape {
  opacity: 1;
  animation: cape-flutter 0.5s ease-in-out infinite alternate;
}
.mascot-result-wrap.super-win .mascot-result {
  animation: super-fly 2.2s ease-in-out 1;
}
@keyframes cape-flutter {
  from { transform: translateX(-50%) rotate(-4deg); }
  to { transform: translateX(-50%) rotate(4deg); }
}
@keyframes super-fly {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  35% { transform: translateY(-10px) rotate(360deg) scale(1.05); }
  60% { transform: translateY(-70px) rotate(360deg) scale(1.1); }
  85% { transform: translateY(-70px) rotate(360deg) scale(1.1); }
  100% { transform: translateY(0) rotate(360deg) scale(1); }
}

/* 連續答錯：慢慢跪倒哭泣，變成北極熊 */
.mascot-tear {
  position: absolute;
  z-index: 3;
  font-size: 14px;
  opacity: 0;
}
.mascot-tear.tear1 { left: 38%; top: 44px; }
.mascot-tear.tear2 { left: 58%; top: 50px; }
.mascot-result-wrap.polar-lose .mascot-result {
  animation: polar-kneel 2.4s ease-in forwards;
}
.mascot-result-wrap.polar-lose .mascot-tear {
  animation: tear-drop 1.6s ease-in 0.6s infinite;
}
.mascot-result-wrap.polar-lose .mascot-tear.tear2 { animation-delay: 1s; }
@keyframes polar-kneel {
  0% { transform: translateY(0) scaleY(1) rotate(0deg); filter: grayscale(0) brightness(1); }
  50% { transform: translateY(10px) scaleY(0.85) rotate(-3deg); filter: grayscale(0.6) brightness(1.3); }
  100% { transform: translateY(16px) scaleY(0.7) rotate(-6deg); filter: grayscale(1) brightness(1.9); }
}
@keyframes tear-drop {
  0% { opacity: 0; transform: translateY(0); }
  20% { opacity: 1; }
  80% { opacity: 1; transform: translateY(18px); }
  100% { opacity: 0; transform: translateY(22px); }
}
#restartBtn {
  display: block;
  margin: 16px auto 0;
}

.submit-score-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed #eadfce;
}
.submit-score-form input {
  padding: 12px 14px;
  font-size: 15px;
  border: 2px solid #eadfce;
  border-radius: 10px;
}
.field-label { font-size: 12px; color: #888; margin: 4px 0 -2px; }
.submit-score-form button {
  cursor: pointer;
}
.submit-score-form button:disabled { opacity: 0.6; cursor: default; }
.submit-msg { font-size: 12px; color: var(--ok); text-align: center; min-height: 16px; margin: 0; }
.submit-msg.error { color: var(--bad); }

.hidden { display: none !important; }
