:root {
  --bg: #eaf6ff;
  --card: #ffffff;
  --ink: #2b2b3a;
  /* 文字同背景對比度要達到 4.5:1（WCAG AA），視力弱啲嘅小朋友都睇得清 */
  --muted: #5c6178;
  --primary: #c2410c;
  --primary-dark: #b23c0b;
  --secondary: #1a6fc4;
  --good: #1e7b34;
  --bad: #c62828;
  --gold: #ffb300;
  --radius: 16px;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.08), 0 8px 24px rgba(40, 80, 140, 0.12);
  --sans: "Microsoft JhengHei", "PingFang HK", "Noto Sans TC", sans-serif;
  --kai: "標楷體", "DFKai-SB", "Kaiti TC", "STKaiti", "Noto Serif TC", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

.kai { font-family: var(--kai); }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* ── 頂欄 ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #dde8f3;
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.icon-btn {
  border: 0;
  background: #eef4fb;
  border-radius: 12px;
  min-width: 40px;
  height: 40px;
  font-size: 1.2rem;
}

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ── 按鈕 ── */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 22px;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { background: var(--secondary); color: #fff; }
.btn.ghost { background: #fff; color: var(--muted); }
.btn.big { font-size: 1.3rem; padding: 16px 44px; }
.btn.small { font-size: 0.9rem; padding: 8px 14px; }
.badge {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #fff;
  color: var(--secondary);
  font-size: 0.85rem;
}
.row-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 20px 0;
}
.hint { color: var(--muted); text-align: center; margin: 8px 0; }

/* ── 首頁 ── */
.hero { text-align: center; padding: 12px 0 4px; }
.hero-bird { font-size: 4rem; animation: bob 1.6s ease-in-out infinite; }
.hero h2 { margin: 8px 0 4px; font-size: 1.5rem; }
.hero p { margin: 0; color: var(--muted); }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-6deg); } }

.stage-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 24px;
}
.stage-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 24px 12px;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.stage-card:hover { transform: translateY(-3px); }
.stage-card.basic { background: linear-gradient(135deg, #2f9447, #1d6e31); }
.stage-card.primary { background: linear-gradient(135deg, #d9561a, #b03a0a); }
.stage-card.junior { background: linear-gradient(135deg, #2f78d6, #1a55b8); }
.stage-card .emoji { font-size: 2.6rem; }
.stage-card b { font-size: 1.6rem; }
.stage-card small { opacity: 0.9; }

.help {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: var(--shadow);
}
.help summary { font-weight: 700; cursor: pointer; }
.help ol { padding-left: 1.3em; line-height: 1.8; margin: 10px 0 4px; }

.help h3 { margin: 14px 0 0; font-size: 1rem; }
kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 6px;
  margin: 0 2px;
  border: 1px solid #b9c6d6;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #fff;
  font: 700 0.95em/1.4 var(--sans);
  text-align: center;
}
kbd.wide { min-width: 4em; }

.ime-chip {
  margin-top: 12px;
  border: 0;
  border-radius: 999px;
  padding: 6px 16px;
  background: #fff;
  box-shadow: var(--shadow);
}
.ime-chip u { color: var(--secondary); }

/* ── 揀輸入法 ── */
.ime-intro { text-align: center; }
.ime-intro h2 { margin: 8px 0; }
.ime-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0 20px;
}
.ime-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 10px;
  border: 3px solid transparent;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.ime-card.on { border-color: var(--primary); }
.ime-card .emoji { font-size: 2.2rem; }
.ime-card b { font-size: 1.4rem; }
.ime-card small { color: var(--muted); text-align: center; }
.ime-card em {
  position: absolute;
  top: -10px;
  right: 10px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-style: normal;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ── 課文清單 ── */
.list { display: grid; gap: 12px; }
.text-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: left;
}
.text-main b { display: block; font-size: 1.5rem; }
.text-main small, .text-meta small { color: var(--muted); }
.text-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 96px;
}
.bar { width: 96px; height: 8px; border-radius: 4px; background: #e6edf5; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--gold); }

/* ── 地圖 ── */
.text-intro {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.text-intro h2 { margin: 0; font-size: 2rem; }
.text-intro .author { margin: 4px 0; color: var(--muted); }
.text-intro .note { margin: 8px 0; }
.fulltext summary { cursor: pointer; color: var(--secondary); font-weight: 700; }
.fulltext p { font-size: 1.3rem; line-height: 1.9; }

.map {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 0;
  background:
    radial-gradient(circle at 20% 10%, #d4f0c4 0 60px, transparent 61px),
    radial-gradient(circle at 80% 60%, #d4f0c4 0 80px, transparent 81px);
}
.node-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(var(--off, 0));
}
.node {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: var(--secondary);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 800;
  box-shadow: 0 5px 0 #2b78cc;
  transition: transform 0.1s;
}
.node:not(.locked):hover { transform: scale(1.08); }
.node.cleared { background: #58c75a; box-shadow: 0 5px 0 #3a9a3c; }
.node.locked { background: #c9d3de; box-shadow: 0 5px 0 #a8b3bf; font-size: 1.2rem; }
.goal span { font-size: 2.4rem; }

.stars i { font-style: normal; color: #d3dae3; font-size: 1rem; }
.stars i.on { color: var(--gold); }

/* ── 預習 ── */
.preview { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 12px; }
.sentence {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  line-height: 1.6;
  text-align: center;
  background: #fffaf0;
  border: 3px solid #f0dcb4;
  border-radius: var(--radius);
  padding: 16px 20px;
  letter-spacing: 0.08em;
}
.opts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}
.seg { display: flex; background: #dfe9f4; border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 620px; }
.mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.mode b { font-size: 1.1rem; }
.mode small { color: var(--muted); line-height: 1.4; }
.mode.on { border-color: var(--primary); background: #fff7f0; }
.speed-row { display: flex; align-items: center; gap: 10px; }
.speed-row[hidden] { display: none; }

/* ── 輸入法提示 ── */
.hint-panel {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--card);
  border: 3px solid #ffe08a;
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.hint-panel { flex: none; flex-wrap: wrap; }
.hint-panel .kb { flex-basis: 100%; margin-top: 0; }
.hint-panel[hidden] { display: none; }
/* 可見高度唔夠（例如手機彈咗鍵盤）：提示變精簡版 */
.compact .hint-panel { padding: 6px 10px; gap: 10px; border-width: 2px; }
.compact .hint-panel .kb, .compact .hint-panel .extra { display: none; }
.compact .hp-char { width: 44px; height: 44px; font-size: 2rem; }
.compact .hp-body p { margin: 0; font-size: 0.9rem; line-height: 1.6; }
.compact .strip { padding: 3px 10px; font-size: 1.3rem; }
.compact #typer { padding: 6px 14px; font-size: 1.3rem; }
.compact .play { gap: 6px; padding: 6px 10px; }
.hp-char {
  flex: none;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  font-size: 3.2rem;
  background: #fffaf0;
  border-radius: 12px;
}
.hp-body { flex: 1; min-width: 0; }
.hp-body p { margin: 2px 0 6px; line-height: 1.7; }
.root { font-family: var(--kai); font-size: 1.3rem; color: var(--primary-dark); margin: 0 2px; }
.py { font-size: 1.3rem; color: var(--primary-dark); }
.kb { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; }
.kb-row { display: flex; gap: 4px; }
.kb-row:nth-child(2) { margin-left: 16px; }
.kb-row:nth-child(3) { margin-left: 40px; }
.key {
  position: relative;
  width: 36px;
  height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #d4dde8;
  border-bottom-width: 3px;
  border-radius: 7px;
  background: #f7f9fc;
  color: #9aa3b5;
  line-height: 1.05;
}
.key b { font-size: 0.8rem; }
.key small { font-family: var(--kai); font-size: 0.95rem; }
.key.on { background: #ffd966; border-color: #e0a800; color: var(--ink); transform: translateY(-2px); }
.key .ord {
  position: absolute;
  top: -9px;
  right: -7px;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}
.mode-tag { font-size: 0.95rem; font-weight: 700; color: var(--good); }

/* ── 遊戲 ── */
/* 玩緊時成個版面固定喺可見範圍（手機鍵盤以上），遊戲畫面佔晒剩低嘅高度 */
body.playing { overflow: hidden; }
body.playing .topbar { display: none; }
.play {
  position: fixed;
  top: var(--vv-top, 0);
  left: 0;
  right: 0;
  height: var(--vv-h, 100dvh);
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}
.hud {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 12px;
  padding: 2px 4px 2px 12px;
}
.hud .icon-btn { min-width: 34px; height: 34px; font-size: 1rem; }
.hearts { font-size: 1.05rem; letter-spacing: 2px; }
.hud-score b { font-size: 1.1rem; }
.combo { flex: 1; color: var(--primary-dark); font-weight: 800; }

.strip {
  position: relative;
  flex: none;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
  font-size: clamp(1.3rem, 5vw, 2rem);
  background: #fffaf0;
  border-radius: 14px;
  padding: 6px 12px;
  scroll-behavior: smooth;
}
.strip::-webkit-scrollbar { display: none; }
.strip span:first-child { margin-left: auto; }
.strip span:last-child { margin-right: auto; }
.strip span { padding: 0 3px; border-radius: 6px; transition: background 0.2s, color 0.2s; }
.strip .done { color: var(--good); }
.strip .missed { color: var(--bad); text-decoration: underline wavy; }
.strip .cur { background: #ffe79a; box-shadow: inset 0 -3px 0 var(--gold); }
.strip.memo .c:not(.done):not(.missed) {
  color: transparent;
  background: #efe3c8;
  margin: 2px;
  border-radius: 6px;
}
.strip.memo .c.cur:not(.done):not(.missed) { background: #ffd966; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 110px;
  max-height: 480px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stage canvas { display: block; width: 100%; height: 100%; }
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
  background: rgba(20, 40, 70, 0.35);
}
.overlay.show { display: flex; }
.count {
  font-size: 6rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  animation: pop 0.8s ease-out;
}
@keyframes pop { from { transform: scale(1.8); opacity: 0; } 30% { opacity: 1; } }
.ov-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  border-radius: var(--radius);
  padding: 20px 28px;
  text-align: center;
}
.ov-box h3 { margin: 0 0 4px; }

.type-row { position: relative; flex: none; }
#typer {
  width: 100%;
  font-size: 1.6rem;
  font-family: var(--kai);
  padding: 10px 18px;
  border: 3px solid var(--secondary);
  border-radius: var(--radius);
  outline: none;
  background: #fff;
  text-align: center;
}
#typer:focus { border-color: var(--primary); box-shadow: 0 0 0 4px #ffd8bd; }
#typer.shake { animation: shake 0.35s; border-color: var(--bad); }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
/* 提示訊息浮喺輸入框上面，唔會推郁版面 */
.msg {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: 3;
  max-width: 94%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  text-align: center;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.msg.show { opacity: 1; }
.msg.bad { color: var(--bad); }

/* ── 結果 ── */
.result { text-align: center; }
.result h2 { font-size: 2rem; margin: 8px 0; }
.big-stars .stars i { font-size: 3rem; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.stats div { background: var(--card); border-radius: 14px; padding: 12px 4px; box-shadow: var(--shadow); }
.stats b { display: block; font-size: 1.5rem; }
.stats small { color: var(--muted); }
.learn-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-top: 12px;
}
.learn-card.trophy { border: 3px solid var(--gold); }
.learn-card h3 { margin: 0; font-size: 1.6rem; }
.learn-card .full { font-size: 1.3rem; line-height: 1.9; margin: 0; }
.weak { margin: 14px 0 0; }
.weak .kai { font-size: 1.4rem; color: var(--bad); }

/* ── 錯字本 ── */
.wb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
.wb-item {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
  padding: 10px 0 6px;
}
.wb-item span { font-size: 2.2rem; display: block; }
.wb-item small { color: var(--bad); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; line-height: 2; font-size: 1.1rem; }

.site-foot {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.site-foot b { color: var(--ink); }
.site-foot a { color: var(--secondary); }
.site-foot small { font-size: 0.75rem; }

/* ── 安裝提示 ── */
.install-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(560px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 12px 14px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(20, 50, 100, 0.25);
  animation: slide-up 0.35s ease-out;
}
.install-banner img { width: 48px; height: 48px; border-radius: 12px; }
.ib-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ib-text small { color: var(--muted); line-height: 1.4; }
.ib-close { border: 0; background: none; color: var(--muted); font-size: 1.1rem; padding: 4px; }
.ios-share { vertical-align: -3px; margin: 0 2px; color: var(--secondary); }
@keyframes slide-up { from { transform: translate(-50%, 120%); } }

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modes { grid-template-columns: 1fr; }
  .stage-card { padding: 16px 6px; }
  .stage-card b { font-size: 1.2rem; }
  .key { width: 27px; height: 36px; }
  .kb-row:nth-child(2) { margin-left: 12px; }
  .kb-row:nth-child(3) { margin-left: 28px; }
  .hp-char { width: 56px; height: 56px; font-size: 2.4rem; }
  .hint-panel .extra { display: none; }
  .hp-body p { font-size: 0.95rem; }
  .text-main b { font-size: 1.3rem; }
}
