:root {
  --bg: #eaf4ff;
  --ink: #28324a;
  --brand: #ff5470;       /* 糖果紅粉 */
  --brand-dark: #e23a59;
  --accent: #ffd23f;      /* 陽光黃 */
  --blue: #3aa0ff;
  --blue-dark: #2476c7;
  --green: #46c97e;
  --green-dark: #2f9b5f;
  --good: #1f9d57; --good-bg: #e6f7ee;
  --bad: #e0483f; --bad-bg: #fdecea;
  --line: #e3e8f2;
  --r: 18px;
  --shadow: 0 8px 0 rgba(0,0,0,.08), 0 10px 24px rgba(31,42,68,.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Fredoka", "PingFang HK", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
b { font-weight: 700; }

/* ---------- HUD ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #ff7a92, var(--brand));
  box-shadow: 0 4px 0 var(--brand-dark), 0 6px 14px rgba(0,0,0,.18);
  color: #fff;
}
.hud-trainer { display: flex; align-items: center; gap: 10px; }
.hud-avatar { width: 40px; height: 40px; background: rgba(255,255,255,.25); border-radius: 12px; padding: 2px; }
.hud-stats { min-width: 150px; }
.hud-line { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.lv-chip { background: var(--accent); color: #6b4d00; font-weight: 700; border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.coins { font-weight: 700; }
.xp-bar { position: relative; height: 12px; background: rgba(0,0,0,.22); border-radius: 999px; margin-top: 4px; overflow: hidden; }
.xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #8fe3ff, #3aa0ff); border-radius: 999px; transition: width .5s ease; }
.xp-text { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 12px; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.4); }
.hud-right { display: flex; align-items: center; gap: 8px; }
.badge-count { font-weight: 700; }
.icon-btn { border: none; background: rgba(255,255,255,.22); color: #fff; border-radius: 12px; padding: 7px 11px; cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: rgba(255,255,255,.38); }

.banner { background: #fff6e5; color: #8a5a00; padding: 9px 16px; font-size: 14px; text-align: center; border-bottom: 1px solid #ffe2ad; }
.banner a { color: var(--brand-dark); font-weight: 700; }

main { max-width: 860px; margin: 0 auto; padding: 16px 14px 60px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.px-sprite { width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ---------- 大地圖 ---------- */
.world {
  position: relative; height: 420px; border-radius: 22px; overflow: hidden;
  border: 4px solid #fff; box-shadow: var(--shadow);
}
.sky { position: absolute; inset: 0; background: linear-gradient(180deg, #7cc7ff, #bfe9ff 55%, #eafaff 70%); }
.sun { position: absolute; top: 16px; right: 24px; font-size: 40px; animation: bob 4s ease-in-out infinite; }
.cloud { position: absolute; font-size: 40px; opacity: .92; }
.cloud.c1 { top: 30px; left: -60px; animation: drift 26s linear infinite; }
.cloud.c2 { top: 70px; left: -120px; font-size: 30px; animation: drift 34s linear infinite; }
.cloud.c3 { top: 14px; left: -200px; font-size: 52px; animation: drift 44s linear infinite; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(140vw); } }
.hills { position: absolute; left: 0; right: 0; bottom: 30%; height: 140px;
  background:
    radial-gradient(120px 80px at 20% 100%, #7fd89a 0 99%, transparent 100%),
    radial-gradient(160px 96px at 60% 100%, #6fce8d 0 99%, transparent 100%),
    radial-gradient(120px 70px at 90% 100%, #7fd89a 0 99%, transparent 100%);
}
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 34%;
  background: linear-gradient(180deg, #69c97f, #4faf68);
  box-shadow: inset 0 6px 0 rgba(255,255,255,.18);
}
.ground::before { /* 小路 */
  content: ""; position: absolute; left: 0; right: 0; top: 38%; height: 26px;
  background: repeating-linear-gradient(90deg, #e8c98a 0 26px, #ddbd79 26px 52px);
  opacity: .85;
}
.world-title { position: absolute; top: 12px; left: 16px; font-weight: 700; font-size: 18px;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.18); background: rgba(0,0,0,.12); padding: 4px 12px; border-radius: 999px; }

.map-buildings { position: absolute; inset: 0; }
.building { position: absolute; bottom: 21%; transform: translateX(-50%); width: 132px; cursor: pointer;
  text-align: center; transition: transform .15s ease; }
.building:hover { transform: translateX(-50%) translateY(-6px) scale(1.04); }
.bld-roof { height: 26px; margin: 0 8px; border-radius: 12px 12px 0 0; clip-path: polygon(0 100%, 50% 0, 100% 100%);
  background: var(--brand); }
.bld-wall { position: relative; height: 62px; background: linear-gradient(180deg, #fff, #f0f3fb);
  border: 3px solid #fff; border-radius: 4px 4px 12px 12px; box-shadow: 0 8px 0 rgba(0,0,0,.10), 0 10px 18px rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center; }
.bld-door { width: 26px; height: 34px; background: #8a5a3c; border-radius: 8px 8px 0 0; align-self: flex-end; }
.bld-sign { position: relative; z-index: 3; margin-top: 8px; display: inline-block; background: var(--accent); color: #6b4d00; font-weight: 700;
  font-size: 13px; padding: 3px 12px; border-radius: 999px; box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.bld-leader { position: absolute; z-index: 1; bottom: 4px; left: -14px; width: 44px; height: 44px;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.25)); }
.bld-badge { position: absolute; top: -8px; left: -8px; font-size: 20px; }

.map-avatar { position: absolute; bottom: 11%; left: 50%; width: 58px; height: 58px; transform: translateX(-50%);
  transition: left .6s ease; filter: drop-shadow(0 4px 4px rgba(0,0,0,.28)); z-index: 5; }
.map-avatar.walking { animation: hop .4s ease-in-out infinite; }
@keyframes hop { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-7px); } }
.map-hint { text-align: center; color: #647089; font-size: 14px; margin-top: 14px; }

/* ---------- 戰鬥舞台 ---------- */
.battle-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.battle-top h2 { margin: 0; font-size: 20px; flex: 1; }

.stage { position: relative; height: 240px; border-radius: 20px; overflow: hidden; border: 4px solid #fff;
  box-shadow: var(--shadow); perspective: 700px; }
.stage-sky { position: absolute; inset: 0; background: linear-gradient(180deg, #aee3ff, #d8f3ff 55%, #eafff0 56%); }
.stage-grass { position: absolute; left: -10%; right: -10%; bottom: -40px; height: 150px; border-radius: 50%;
  background: radial-gradient(closest-side, #7fd89a, #5cbf7c); transform: rotateX(55deg); box-shadow: 0 0 40px rgba(0,0,0,.08) inset; }
.monster-zone { position: absolute; top: 28px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; }
.monster-sprite { width: 104px; height: 104px; animation: bob 2.2s ease-in-out infinite; font-size: 80px; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.monster-sprite.shake { animation: shake .45s ease infinite; }
.monster-sprite.caught { animation: caught .6s ease forwards; }
.monster-sprite.flee { animation: flee .6s ease forwards; }
@keyframes shake { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-12deg)} 75%{transform:rotate(12deg)} }
@keyframes caught { 0%{transform:scale(1)} 50%{transform:scale(1.3)} 100%{transform:scale(.7);opacity:.45;filter:grayscale(.4)} }
@keyframes flee { 0%{transform:translateX(0);opacity:1} 100%{transform:translateX(60px) scale(.8);opacity:.15} }
.monster-shadow { width: 80px; height: 16px; margin-top: 4px; background: rgba(0,0,0,.22); border-radius: 50%; filter: blur(2px); }
.stage-info { position: absolute; top: 12px; left: 14px; background: rgba(255,255,255,.9); border-radius: 12px;
  padding: 6px 12px; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.monster-name { font-weight: 700; font-size: 15px; }
.badge-progress { font-size: 14px; margin-top: 2px; }
.stage-trainer { position: absolute; bottom: 8px; left: 18px; width: 62px; height: 62px; transform: scaleX(-1);
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.28)); }

/* ---------- 對話框 ---------- */
.dialog { background: #fff; border: 4px solid #ffe08a; border-radius: 18px; padding: 18px 20px; margin-top: 16px;
  box-shadow: var(--shadow); }
.q-text { font-size: 21px; font-weight: 700; min-height: 28px; white-space: pre-wrap; }
.loading, .error { color: #8a93a8; font-weight: 500; font-size: 16px; }
.error { color: var(--bad); }
.answer-area { margin: 14px 0; }
.text-input { width: 100%; padding: 13px 14px; font-size: 17px; border: 3px solid var(--line); border-radius: 14px;
  font-family: inherit; outline: none; }
.text-input:focus { border-color: var(--blue); }
.ans-preview:not(:empty) { margin-top: 10px; font-size: 18px; background: #f1f7ff; border: 2px dashed #b9d8ff;
  border-radius: 12px; padding: 8px 12px; }
.hint-box:not(:empty) { background: #fff8e8; border: 2px solid #ffe6b0; padding: 10px 12px; border-radius: 12px;
  margin-bottom: 12px; font-size: 14px; color: #7a5a00; }
.q-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.primary-btn { background: var(--brand); color: #fff; border: none; border-radius: 14px; padding: 12px 22px;
  font-size: 16px; font-weight: 700; cursor: pointer; font-family: inherit; box-shadow: 0 4px 0 var(--brand-dark); }
.primary-btn:hover { transform: translateY(2px); box-shadow: 0 2px 0 var(--brand-dark); }
.primary-btn:disabled { opacity: .6; cursor: default; box-shadow: none; transform: none; }
.text-btn { background: none; border: none; color: var(--blue-dark); cursor: pointer; font-size: 15px; font-weight: 600; font-family: inherit; padding: 6px; }
.text-btn:hover { text-decoration: underline; }

/* 回饋 */
.feedback:not(:empty) { margin-top: 16px; padding: 16px; border-radius: 14px; }
.feedback.correct { background: var(--good-bg); border: 2px solid #b6e6c9; }
.feedback.wrong { background: var(--bad-bg); border: 2px solid #f4c4bf; }
.feedback.neutral { background: #f1f4fb; border: 2px solid #d3ddf0; }
.fb-head { font-weight: 700; font-size: 18px; margin-bottom: 6px; }
.feedback.correct .fb-head { color: var(--good); }
.feedback.wrong .fb-head { color: var(--bad); }
.feedback.neutral .fb-head { color: var(--blue-dark); }
.fb-text { white-space: pre-wrap; }
.fb-sol { margin-top: 10px; }
.fb-sol summary { cursor: pointer; font-weight: 700; color: var(--blue-dark); }
.fb-sol > div { margin-top: 8px; white-space: pre-wrap; color: #2b3550; line-height: 1.9; }
.fb-adjust { margin-top: 10px; font-size: 13px; color: #647089; }

/* 博士 */
.prof-card { margin-top: 16px; background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); }
.prof-card summary { font-weight: 700; cursor: pointer; }
.prof-log { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 4px 4px; }
.bubble { padding: 10px 14px; border-radius: 14px; max-width: 86%; font-size: 15px; white-space: pre-wrap; }
.bubble.assistant { background: #eef3fe; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.user { background: var(--blue); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.pending { opacity: .65; font-style: italic; }
.bubble.err { background: var(--bad-bg); color: var(--bad); align-self: flex-start; }
.prof-input-row { display: flex; gap: 10px; margin-top: 10px; }
.prof-input-row textarea { flex: 1; resize: none; padding: 11px 14px; border: 2px solid var(--line); border-radius: 12px; font-family: inherit; font-size: 15px; outline: none; }
.prof-input-row textarea:focus { border-color: var(--blue); }

/* ---------- 圖鑑 ---------- */
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.dex-card { background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.dex-card.caught { border-color: var(--accent); }
.dex-sprite { width: 72px; height: 72px; margin: 0 auto; }
.dex-card.locked .dex-sprite { filter: brightness(0) opacity(.18); }
.dex-name { font-weight: 700; margin-top: 6px; }
.dex-num { font-size: 13px; color: #647089; }

/* ---------- 分數直式 ---------- */
.frac { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; vertical-align: middle; margin: 0 3px; line-height: 1.05; }
.frac .num { display: block; padding: 0 4px; }
.frac .den { display: block; padding: 1px 4px 0; border-top: 2px solid currentColor; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,28,48,.55); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 18px; }
.modal-box { background: #fff; border-radius: var(--r); padding: 26px; max-width: 460px; width: 100%; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0 0 10px; }
.modal-note { font-size: 13px; color: #647089; margin: 0 0 16px; }
.modal-note a { color: var(--brand-dark); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.pop-box { text-align: center; border: 4px solid var(--accent); }
.big-emoji { font-size: 64px; animation: pop .5s ease; }
@keyframes pop { 0%{transform:scale(0) rotate(-25deg)} 70%{transform:scale(1.25)} 100%{transform:scale(1)} }
.pop-box h3, .pop-box p { font-size: 18px; margin: 8px 0 18px; }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .world { height: 340px; }
  .hud-stats { min-width: 120px; }
  .battle-top h2 { font-size: 17px; }
  .dex-grid { grid-template-columns: repeat(2, 1fr); }
}
