:root {
  --bg: #fff7ec;
  --card: #ffffff;
  --ink: #3b2a1e;
  --muted: #9a8473;
  --line: #f1dcc8;
  --accent: #ff8a3d;
  --accent-ink: #c2410c;
  --good: #22a55b;
  --good-bg: #e6f8ee;
  --bad: #e5484d;
  --bad-bg: #fdecec;
  --blue: #2563eb;
  --star: #f5b301;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "PingFang SC", "Hiragino Sans GB", serif;
  --ui: -apple-system, "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--ui); }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
#app { min-height: 100%; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* header */
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.bar h1 { flex: 1; margin: 0; font-size: 22px; text-align: center; }
.bar .back, .bar .side { min-width: 64px; height: 44px; border-radius: 14px; font-size: 22px; }
.bar .back { background: var(--card); box-shadow: 0 2px 0 var(--line); }
.bar .side { text-align: right; font-weight: 700; font-size: 18px; color: var(--accent-ink); }
.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px 24px; flex: 1; display: flex; flex-direction: column; gap: 14px; }

/* cards & buttons */
.card { background: var(--card); border-radius: 22px; padding: 16px; box-shadow: 0 3px 0 var(--line); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 18px; border-radius: 16px; background: var(--card); box-shadow: 0 3px 0 var(--line); font-size: 19px; font-weight: 600; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-ink); }
.btn.on { background: #fff1e4; outline: 2px solid var(--accent); }
.btn.small { min-height: 44px; font-size: 16px; padding: 0 14px; }
.btn[disabled] { opacity: .4; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.tip { color: var(--muted); font-size: 15px; text-align: center; }

/* home */
.hero { text-align: center; padding: 12px 0 0; }
.hero h1 { font-size: 34px; margin: 6px 0; }
.totals { display: flex; justify-content: center; gap: 12px; }
.pill { background: var(--card); border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 18px; box-shadow: 0 2px 0 var(--line); }
.listcard { display: flex; flex-direction: column; gap: 10px; text-align: left; width: 100%; }
.listcard .t { font-size: 26px; font-weight: 800; font-family: var(--kai); }
.listcard .l { color: var(--muted); }
.meter { height: 14px; background: #f6e7d8; border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, #ffb23d, #ff8a3d); border-radius: 99px; transition: width .6s; }
.trophy { font-size: 30px; }

/* list screen */
.mainmode { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 16px; background: var(--accent); color: #fff; border-radius: 24px; box-shadow: 0 4px 0 var(--accent-ink); width: 100%; }
.mainmode .big { font-size: 30px; font-weight: 800; }
.mainmode .sub { font-size: 17px; opacity: .95; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.mode { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; }
.mode .e { font-size: 30px; }
.mode .n { font-size: 18px; font-weight: 700; }
.mode .s { font-size: 13px; color: var(--muted); }
.items { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; text-align: left; width: 100%; }
.item .no { color: var(--muted); width: 26px; }
.item .tx { flex: 1; font-family: var(--kai); font-size: 22px; }
.stars { color: var(--star); letter-spacing: 1px; font-size: 18px; white-space: nowrap; }
.stars .off { color: #e9dccd; }
.pet { font-size: 24px; }
.pet.no { filter: grayscale(1); opacity: .25; }

/* hanzi with pinyin */
.hz { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 2px 4px; }
.ch { display: inline-flex; flex-direction: column; align-items: center; }
.ch .py { font-size: .32em; color: var(--accent-ink); min-height: 1.3em; font-family: var(--ui); }
.ch .c { font-family: var(--kai); line-height: 1.15; }
.ch .c.hidden { width: 1em; height: 1em; margin: .07em 0; border: 2px dashed #f0b48c; border-radius: 8px; color: transparent; background: #fffaf4; }
.ch.punct .c { color: var(--muted); }
.en { text-align: center; color: var(--muted); font-size: 18px; }

/* writing */
.prog { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; font-family: var(--kai); font-size: 30px; }
.prog span { width: 1.2em; height: 1.2em; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; background: #fffaf4; border: 1.5px solid var(--line); }
.prog span.done { background: var(--good-bg); border-color: #a6e3bf; }
.prog span.cur { border: 2.5px solid var(--accent); background: #fff1e4; }
.prog span.p { border: 0; background: none; width: .6em; color: var(--muted); }
.wbox { position: relative; margin: 0 auto; background: #fffdf7; border: 3px solid #e7a989; border-radius: 12px; }
.wbox svg.grid { position: absolute; inset: 0; pointer-events: none; }
.wbox .target { position: absolute; inset: 0; touch-action: none; }
.curpy { text-align: center; font-size: 26px; color: var(--accent-ink); min-height: 34px; }

/* free-writing pad */
.padwrap { position: relative; flex: 1; min-height: 360px; border-radius: 18px; overflow: hidden; box-shadow: 0 3px 0 var(--line); }
.padwrap canvas { position: absolute; inset: 0; touch-action: none; }
.qnum { font-size: 22px; font-weight: 800; }

/* quiz */
.qcard { text-align: center; padding: 26px 16px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt { min-height: 76px; font-size: 24px; border-radius: 18px; background: var(--card); box-shadow: 0 3px 0 var(--line); padding: 8px; }
.opt.hz-opt { font-family: var(--kai); font-size: 30px; }
.opt.right { background: var(--good-bg); outline: 3px solid var(--good); }
.opt.wrong { background: var(--bad-bg); outline: 3px solid var(--bad); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* dictation review */
.rv { display: flex; flex-direction: column; gap: 10px; }
.rv img { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: #fffdf7; }
.rv .ans { display: flex; flex-wrap: wrap; gap: 4px; font-family: var(--kai); font-size: 30px; }
.rv .ans button { min-width: 1.3em; padding: 2px 4px; border-radius: 8px; background: #fffaf4; border: 1.5px solid var(--line); font-family: var(--kai); }
.rv .ans button.x { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.rv .marks { display: flex; gap: 10px; }
.rv .ok.on { background: var(--good-bg); outline: 2px solid var(--good); }
.rv .ng.on { background: var(--bad-bg); outline: 2px solid var(--bad); }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(59, 42, 30, .35); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.panel { background: var(--card); border-radius: 26px; padding: 24px; max-width: 460px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 14px; animation: pop .25s ease-out; }
.panel .big { font-size: 56px; }
.panel h2 { margin: 0; font-size: 26px; }
.panel .stars { font-size: 40px; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.stars .gain { display: inline-block; animation: starpop .6s ease-out both; }
@keyframes starpop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.4); } 100% { transform: scale(1); } }

#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
#fx span { position: absolute; top: -40px; font-size: 30px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* stickers */
.book { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.sticker { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; }
.sticker .pet { font-size: 46px; }
.sticker .w { font-family: var(--kai); font-size: 15px; text-align: center; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* settings */
.set { display: flex; flex-direction: column; gap: 10px; }
.set h3 { margin: 4px 0; font-size: 18px; }
select { font: inherit; font-size: 17px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 100%; }

/* paper drill */
.btn.huge { min-height: 72px; font-size: 24px; width: 100%; }
.btn.ok-big { background: var(--good-bg); outline: 3px solid var(--good); color: #13703b; }
.btn.ng-big { background: var(--bad-bg); outline: 3px solid var(--bad); color: var(--bad); }
.ch.x .c { color: var(--bad); background: var(--bad-bg); border-radius: 10px; }
.ch.x .py { color: var(--bad); }
button.ch { padding: 0 2px; }
.ngnote { color: var(--bad); font-weight: 700; text-align: center; }
.panel { max-height: 92vh; overflow-y: auto; }
.nostroke { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--kai); color: #c2410c; }

.strokename { text-align: center; font-size: 24px; font-weight: 700; color: var(--accent-ink); min-height: 32px; }
