/* Mandarin Land — same storybook-meadow look as Spelling Land, with textbook-style zhuyin */
:root {
  --pink: #FF3D7A;
  --mint: #2FC79E;
  --blue: #3797FF;
  --orange: #FF9933;
  --purple: #A77BFF;
  --yellow: #FBC920;
  --ink: #3B2F4A;
  --soft: #7A716A;
  --paper: #FFFDF7;
  --radius: 24px;
  --shadow: 0 5px 0 rgba(59, 47, 74, .1);
  --card-shadow: 0 10px 26px rgba(91, 75, 219, .13), 0 3px 0 rgba(59, 47, 74, .06);
  --font-title: "Baloo 2", "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  /* 楷書 like Taiwan textbooks */
  --font-han: "LXGW WenKai TC", "TW-Kai", "BiauKai", "DFKai-SB", "標楷體", "Kaiti TC", "STKaiti", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body); color: var(--ink);
  background: linear-gradient(180deg, #CDE9FF 0%, #E9F5FF 42%, #FFF5E2 100%);
  -webkit-font-smoothing: antialiased; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; border: 0; color: inherit; background: none; padding: 0; }

/* background scene */
#scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
#scene .hills { position: absolute; left: 0; bottom: 0; width: 100%; height: 24vh; min-height: 120px; }
#scene .puff { position: absolute; background: #fff; border-radius: 999px; opacity: .92; animation: puffDrift linear infinite; }
#scene .puff::before, #scene .puff::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
#scene .puff::before { width: 46%; height: 150%; left: 16%; bottom: 20%; }
#scene .puff::after { width: 34%; height: 120%; left: 52%; bottom: 25%; }
@keyframes puffDrift { from { transform: translateX(-25vw); } to { transform: translateX(125vw); } }
/* Taiwan: 玉山 ridge, 臺北101, and 平溪天燈 drifting up */
#scene .peaks { position: absolute; left: 0; bottom: 14vh; width: 100%; height: 26vh; min-height: 140px; }
#scene .t101 { position: absolute; right: 7%; bottom: 13vh; height: 34vh; min-height: 170px; opacity: .55; }
#scene .lantern {
  position: absolute; bottom: -90px; width: 34px; height: 46px; border-radius: 40% 40% 22% 22% / 30% 30% 18% 18%;
  background: linear-gradient(180deg, #FFE08A 0%, #FFB547 55%, #FF7A45 100%);
  box-shadow: 0 0 22px 6px rgba(255, 190, 90, .45);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-han); font-size: 11px; font-weight: 700; color: #B8321F; writing-mode: vertical-rl;
  animation: lanternUp linear infinite; opacity: .85;
}
#scene .lantern::after { content: ""; position: absolute; bottom: -5px; left: 30%; width: 40%; height: 5px; border-radius: 0 0 6px 6px; background: #FFE9A8; }
@keyframes lanternUp {
  0% { transform: translate(0, 0) rotate(-3deg); opacity: 0; }
  8% { opacity: .85; }
  50% { transform: translate(24px, -55vh) rotate(3deg); }
  92% { opacity: .75; }
  100% { transform: translate(-10px, -115vh) rotate(-2deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { #scene .lantern, #scene .puff, .bear { animation: none; } #scene .lantern { display: none; } }

#app { position: relative; z-index: 1; height: 100%; }
.screen { height: 100%; display: flex; flex-direction: column; animation: fadeIn .25s ease; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 18px 40px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-title); font-weight: 700; font-size: 22px;
  padding: 10px 26px; border-radius: 999px; background: var(--paper);
  border: 3px solid #fff; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.btn.pink { background: var(--pink); color: #fff; }
.btn.mint { background: var(--mint); color: #fff; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 18px; flex: 0 0 auto;
  background: var(--paper); border: 3px solid #fff; box-shadow: var(--shadow);
  font-size: 24px; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .1s;
}
.icon-btn:active { transform: translateY(3px); }
.icon-btn.small { width: 42px; height: 42px; font-size: 19px; border-radius: 14px; }
.say { margin-left: 10px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; flex: 0 0 auto; }
.topbar .spacer { flex: 1; }
.tb-title { font-family: var(--font-title); font-weight: 800; font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pill {
  background: rgba(255,255,255,.85); border: 3px solid #fff; border-radius: 999px; padding: 6px 14px;
  font-family: var(--font-title); font-weight: 700; font-size: 18px; box-shadow: 0 4px 0 rgba(59,47,74,.08);
  white-space: nowrap;
}
.zy-toggle { color: var(--soft); }
.zy-toggle.on { color: var(--pink); }

/* ---------- characters ---------- */
/* a character with its zhuyin in a narrow column on the right, like 國語課本 */
.hz {
  display: inline-flex; align-items: center; cursor: pointer; border-radius: .14em;
  padding: 0 .04em; transition: background .15s; vertical-align: middle;
}
.hz:hover { background: rgba(255, 61, 122, .1); }
.hz .g { font-family: var(--font-han); font-weight: 700; line-height: 1.15; }
.hz.tapped .g { animation: tapPop .35s ease; color: var(--pink); }
@keyframes tapPop { 40% { transform: scale(1.22); } }
.zy {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-han); font-size: .34em; line-height: 1.02; margin-left: .1em; min-width: 1em;
  position: relative; color: #5B4E6B; font-weight: 400;
}
.zy .zs { position: relative; display: block; }
/* the Kai font draws ˇ like a check mark; use a plain face for tone marks */
.zy .tn, .zy .nt { font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif; font-weight: 700; }
.zy .tn { position: absolute; left: 100%; top: -.2em; margin-left: .02em; }
.zy .nt { display: block; line-height: .6; }
body.nozy .zy { display: none; }
.pn { font-family: var(--font-han); }
.hz.blank .g {
  display: inline-block; width: 1.05em; height: 1.1em; border: .06em dashed var(--pink); border-radius: .16em;
  background: #FFF0F5; vertical-align: middle;
}
.hz.filled .g { color: var(--mint); animation: tapPop .45s ease; }
.hz.big .g { font-size: 1em; }

/* ---------- mascot ---------- */
.mascot { display: flex; align-items: flex-end; gap: 10px; margin: 6px auto 14px; max-width: 760px; width: 100%; }
.bear { width: 66px; flex: 0 0 auto; cursor: pointer; animation: bob 3s ease-in-out infinite; }
.bear svg { display: block; width: 100%; height: auto; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.bubble {
  background: var(--paper); border: 3px solid #fff; border-radius: 22px; padding: 12px 18px; position: relative;
  font-family: var(--font-han); font-size: 24px; font-weight: 700; box-shadow: var(--card-shadow); cursor: pointer;
}
.bubble::before {
  content: ""; position: absolute; left: -14px; bottom: 16px;
  border: 8px solid transparent; border-right: 10px solid var(--paper);
}
.bubble .sub { font-family: var(--font-body); font-size: 15px; font-weight: 600; color: var(--soft); margin-top: 2px; }

/* ---------- home ---------- */
.home { max-width: 1100px; width: 100%; margin: 0 auto; }
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 26px; margin: 4px 0 10px; }
.hero .mascot { margin: 0; width: auto; }
.wordmark { display: flex; flex-direction: column; }
.wm-en { font-family: var(--font-title); font-weight: 800; font-size: 50px; line-height: 1; color: var(--pink); text-shadow: 0 4px 0 #fff; }
.wm-zh { font-family: var(--font-han); font-weight: 700; font-size: 34px; letter-spacing: .25em; color: var(--ink); }
.grade { margin: 18px 0; }
.grade h2 { margin: 0 0 10px; display: flex; align-items: baseline; gap: 12px; }
.grade .gname { font-family: var(--font-han); font-size: 28px; background: var(--gc); color: #fff; padding: 2px 16px; border-radius: 999px; }
.grade .gen { font-family: var(--font-title); font-size: 18px; color: var(--soft); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.lesson-tile {
  background: var(--paper); border: 4px solid var(--wc, #fff); border-radius: var(--radius); box-shadow: var(--card-shadow);
  padding: 16px 18px; text-align: left; position: relative; display: flex; flex-direction: column; gap: 4px;
  transition: transform .12s; min-height: 150px;
}
.lesson-tile:hover { transform: translateY(-3px); }
.lesson-tile .lnum {
  width: 34px; height: 34px; border-radius: 50%; background: var(--wc); color: #fff;
  font-family: var(--font-title); font-weight: 800; font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.lesson-tile .licon { position: absolute; right: 14px; top: 10px; font-size: 38px; }
.lesson-tile .ltitle { font-family: var(--font-han); font-weight: 700; font-size: 24px; }
.lesson-tile .len { font-size: 15px; color: var(--soft); }
.lesson-tile .lchars { font-family: var(--font-han); font-size: 22px; letter-spacing: .1em; }
.lesson-tile .lstars { font-size: 16px; font-weight: 800; }
.lesson-tile.locked { background: rgba(239, 234, 226, .85); border-color: transparent; color: #A79F95; cursor: default; justify-content: center; min-height: 110px; }
.lesson-tile.locked:hover { transform: none; }
.lesson-tile.locked .licon { filter: grayscale(1); opacity: .5; font-size: 28px; }
/* grade tabs */
.gtabs { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 16px; }
.gtab {
  display: flex; flex-direction: column; align-items: center; padding: 6px 16px 4px; border-radius: 18px;
  background: rgba(255,255,255,.75); border: 3px solid #fff; box-shadow: 0 4px 0 rgba(59,47,74,.08);
  transition: transform .1s;
}
.gtab:hover { transform: translateY(-2px); }
.gtab .gname { font-family: var(--font-han); font-weight: 700; font-size: 22px; }
.gtab .gen { font-size: 12px; color: var(--soft); font-weight: 700; }
.gtab.on { background: var(--gc); border-color: var(--gc); color: #fff; }
.gtab.on .gen { color: rgba(255,255,255,.85); }
.credit {
  display: block; width: max-content; margin: 44px auto 70px; font-size: 11px; color: rgba(59,47,74,.32);
  text-decoration: none; letter-spacing: .04em;
}
.credit:hover { color: rgba(59,47,74,.6); text-decoration: underline; }

/* ---------- lesson ---------- */
.lesson { max-width: 900px; width: 100%; margin: 0 auto; }
.lhead { font-size: 52px; margin: 0 0 14px; text-align: center; font-weight: 400; }
.lhead .gap { display: inline-block; width: .5em; }
.char-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 22px; }
.char-chip {
  background: var(--paper); border: 3px solid #fff; border-radius: 20px; box-shadow: var(--card-shadow);
  padding: 6px 12px 4px; display: flex; flex-direction: column; align-items: center; font-size: 46px;
}
.char-chip .em { font-size: 22px; }
.char-row.small { font-size: 40px; gap: 6px; }
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.game-btn {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius); color: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,.14); text-align: left; transition: transform .12s;
}
.game-btn:hover { transform: translateY(-3px); }
.game-btn.pink { background: var(--pink); } .game-btn.blue { background: var(--blue); } .game-btn.mint { background: var(--mint); }
.game-btn.orange { background: var(--orange); } .game-btn.purple { background: var(--purple); }
.game-btn .gicon { font-size: 36px; }
.game-btn .gtext { display: flex; flex-direction: column; }
.game-btn .gname { font-family: var(--font-han); font-weight: 700; font-size: 28px; line-height: 1.1; }
.game-btn .gen { font-size: 15px; opacity: .9; }
.game-btn .gstars { margin-left: auto; font-size: 22px; white-space: nowrap; }
.star { color: #FFC21A; text-shadow: 0 2px 0 rgba(0,0,0,.1); }
.star.off { color: rgba(255,255,255,.55); text-shadow: none; }
.results .star.off { color: #E2DCD2; }

/* ---------- play ---------- */
.play { max-width: 820px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.card {
  background: var(--paper); border: 4px solid #fff; border-radius: 30px; box-shadow: var(--card-shadow);
  padding: 22px; width: 100%;
}
.card.shake { animation: shake .35s ease; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }

.learn-card { display: flex; flex-direction: column; gap: 18px; }
.lc-top { display: flex; align-items: center; justify-content: center; gap: 30px; }
.lc-big { font-size: min(200px, 34vw); line-height: 1; }
.lc-pic { font-size: min(110px, 20vw); }
.lc-line { font-size: 34px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; }
.lc-words { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.word-chip {
  display: flex; align-items: center; gap: 8px; background: #FFF6D1; border-radius: 20px; padding: 6px 12px;
  font-size: 44px;
}
.word-chip .em { font-size: 34px; }
.nav-row { display: flex; align-items: center; gap: 16px; margin-top: 18px; }
.dots { display: flex; gap: 7px; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: rgba(0,0,0,.12); }
.dots span.seen { background: #FFB3CB; }
.dots span.on { background: var(--pink); transform: scale(1.3); }

.progress { width: 100%; height: 14px; background: rgba(255,255,255,.7); border-radius: 999px; margin: 4px 0 14px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--mint); border-radius: 999px; transition: width .4s; }
.quiz-card { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 230px; justify-content: center; }
.prompt { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.big-say {
  width: 150px; height: 150px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 70px;
  box-shadow: 0 8px 0 rgba(0,0,0,.15); animation: pulse 1.8s ease-in-out infinite;
}
.prompt .hz.big { font-size: 130px; }
.big-pic { font-size: min(130px, 30vw); line-height: 1.1; }
.big-pic.sm { font-size: 70px; }
.fill-text { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; }
.fill-text.word { font-size: 84px; }
.fill-text.sentence { font-size: 52px; }
.hint-row { display: flex; align-items: center; gap: 4px; }
.hint-label { font-size: 15px; color: var(--soft); font-weight: 700; }
.opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: 100%; margin-top: 18px; }
.opt {
  background: var(--paper); border: 4px solid #fff; border-radius: 26px; box-shadow: 0 7px 0 rgba(59,47,74,.12);
  font-size: 84px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .2s;
}
.opt .g { font-family: var(--font-han); font-weight: 700; }
.opt .hz { pointer-events: none; }
.opt:active { transform: translateY(4px); }
.opt.right { background: #C9F5E5; border-color: var(--mint); }
.opt.wrong { background: #FFD9D3; opacity: .5; animation: shake .3s ease; }
.opt.pulse { animation: pulse 1s ease-in-out infinite; border-color: var(--yellow); }
@keyframes pulse { 50% { transform: scale(1.06); } }
.next-btn { margin-top: 18px; }
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 12px; }
  .tb-title { font-size: 19px; }
  .pill { font-size: 16px; padding: 5px 10px; }
  .opts { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .opt { aspect-ratio: auto; height: 104px; font-size: 64px; }
  .quiz-card { min-height: 0; padding: 16px; }
  .big-say { width: 120px; height: 120px; font-size: 56px; }
  .fill-text.sentence { font-size: 38px; }
  .lc-line { font-size: 26px; }
  .word-chip { font-size: 36px; }
  .lhead { font-size: 40px; }
  .wm-en { font-size: 40px; }
  .bubble { font-size: 20px; }
}

/* ---------- results ---------- */
.results { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.big-stars { font-size: 80px; display: flex; gap: 12px; }
.big-stars span { animation: starIn .5s cubic-bezier(.3,1.8,.5,1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); opacity: 0; } }
.res-btns { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 10px; }
.confetti { position: fixed; top: 0; width: 12px; height: 12px; border-radius: 3px; pointer-events: none; z-index: 70; }
