:root {
  --paper: #F6F1E8;
  --card: #FFFDF9;
  --ink: #1C1A17;
  --muted: #7B746A;
  --line: #E4DCCD;
  --seal: #B83A26;
  --ok: #3E7D55;
  --bad: #B83A26;
  --t1: #C0392B;
  --t2: #D07A1E;
  --t3: #3E8A5A;
  --t4: #2E5AA6;
  --t5: #8E877C;
  --hz: "Noto Serif SC", "Songti SC", "STSong", serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--ui); font-size: 16px; line-height: 1.45; }
body { min-height: 100dvh; }
#app { max-width: 560px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
a { color: inherit; }
.hz { font-family: var(--hz); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; margin-bottom: 18px; }
.top h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .01em; }
.back { width: 40px; height: 40px; margin-left: -10px; display: grid; place-items: center; font-size: 22px; }
.top .right { font-size: 14px; color: var(--muted); min-width: 40px; text-align: right; }

/* home */
.brand { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 0 22px; }
.brand h1 { font-family: var(--hz); font-size: 34px; font-weight: 700; margin: 0; letter-spacing: .02em; }
.brand h1 b { color: var(--seal); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-bottom: 22px; }
.stat { background: var(--card); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .n span { font-size: 15px; color: var(--muted); font-weight: 400; }
.stat .l { font-size: 13px; color: var(--muted); }
.bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--seal); }

.menu { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.menu button { display: flex; align-items: center; gap: 16px; padding: 16px 2px; border-bottom: 1px solid var(--line); text-align: left; }
.menu .ic { font-family: var(--hz); font-size: 26px; width: 34px; text-align: center; color: var(--seal); }
.menu .tx { flex: 1; }
.menu .tx b { display: block; font-weight: 600; }
.menu .tx span { font-size: 13px; color: var(--muted); }
.menu .badge { font-size: 13px; font-variant-numeric: tabular-nums; background: var(--ink); color: var(--paper); border-radius: 99px; padding: 2px 9px; }
.menu .badge.zero { background: transparent; color: var(--muted); }
.foot { margin-top: 22px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }

/* card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; min-height: 340px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; position: relative; }
.card .big { font-family: var(--hz); font-size: clamp(64px, 22vw, 104px); line-height: 1.1; letter-spacing: .04em; }
.card .big.long { font-size: clamp(48px, 15vw, 76px); }
.card .tag { position: absolute; top: 14px; left: 16px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.py { font-size: 24px; letter-spacing: .02em; }
.vi { font-size: 18px; margin-top: 4px; }
.hv { font-size: 13px; color: var(--muted); margin-top: 6px; letter-spacing: .04em; }
.hv b { font-weight: 500; color: var(--ink); text-transform: lowercase; }
.reveal { margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sp { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; margin-top: 14px; font-size: 18px; }
.sp:active { background: var(--paper); }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }

.chars { width: 100%; margin-top: 20px; border-top: 1px solid var(--line); text-align: left; }
.ch { display: grid; grid-template-columns: 52px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ch .c { font-family: var(--hz); font-size: 38px; line-height: 1; text-align: center; }
.ch .h { font-size: 14px; }
.ch .h b { font-weight: 600; text-transform: lowercase; }
.ch .m { font-size: 14px; color: var(--muted); margin-top: 2px; }
.ch .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* buttons */
.row { display: flex; gap: 8px; margin-top: 14px; }
.btn { flex: 1; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 500; padding: 8px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.btn small { font-size: 11px; color: var(--muted); font-weight: 400; }
.btn.pri { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.pri small { color: #bdb5a8; }
.btn.g0 { color: var(--bad); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; }
.link { color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
#act { position: sticky; bottom: 0; padding: 4px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(246,241,232,0), var(--paper) 22%); }
.progress { height: 3px; background: var(--line); border-radius: 2px; margin: -8px 0 16px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); transition: width .2s; }

/* pinyin input */
.inp { width: 100%; margin-top: 18px; font-size: 22px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); text-align: center; outline: none; }
.inp:focus { border-color: var(--ink); }
.keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 10px; width: 100%; }
.keys button { height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); font-size: 17px; }
.verdict { margin-top: 14px; font-weight: 600; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.answer { margin-top: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.answer .hz { font-size: 30px; }

/* quiz */
.q-prompt { margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.lsn { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 18px 0 8px; }
.lsn .sp { width: 76px; height: 76px; font-size: 28px; }
.card.lcard { min-height: 0; padding-top: 18px; padding-bottom: 18px; }
.lcard .lsn { margin: 12px 0 0; }
.opts { display: grid; gap: 8px; margin-top: 14px; }
.opt { min-height: 56px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; display: flex; align-items: center; gap: 10px; }
.opt.hzopt { font-family: var(--hz); font-size: 28px; justify-content: center; }
.opt.pyopt { font-size: 20px; justify-content: center; }
.opt.right { border-color: var(--ok); background: #EEF5EF; }
.opt.wrong { border-color: var(--bad); background: #F8ECE9; }
.opt:disabled { cursor: default; }

/* writing */
.wr { display: flex; flex-direction: column; align-items: center; }
.pad { position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 16px; touch-action: none; }
.pad svg.grid { position: absolute; inset: 0; pointer-events: none; }
.wr-info { text-align: center; margin-bottom: 12px; }
.wr-info .vi { font-size: 16px; }
.meo { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-top: 12px; width: 100%; text-align: left; }
.meo b { font-weight: 600; }
.step { font-size: 13px; color: var(--muted); margin: 10px 0 0; text-align: center; }

/* list */
.search { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); outline: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); font-size: 13px; background: var(--card); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.list { border-top: 1px solid var(--line); margin-top: 6px; }
.li { display: grid; grid-template-columns: 8px 92px 1fr; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.li .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.li .dot.l { background: var(--t2); } .li .dot.m { background: var(--ok); }
.li .w { font-family: var(--hz); font-size: 22px; }
.li .p { font-size: 14px; }
.li .v { font-size: 13px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* settings */
.sec { margin-top: 22px; }
.sec h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.field { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.field select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.field input[type=password], .field input[type=text] { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0; }
.note ol { padding-left: 18px; margin: 6px 0; }

/* done */
.done { text-align: center; padding: 40px 0 10px; }
.done .big { font-family: var(--hz); font-size: 64px; color: var(--seal); }
.done h2 { margin: 6px 0; font-size: 20px; }
.miss { text-align: left; margin-top: 18px; border-top: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 99px; font-size: 14px; z-index: 9; max-width: 90vw; }

@media (min-width: 700px) { #app { padding-top: 40px; } }

/* basic strokes */
.stks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stk { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stk b { font-size: 13px; font-weight: 600; }
.stk span { font-size: 11px; color: var(--muted); }
.stk.done { border-color: var(--ok); }
.stk.done b::after { content: " ✓"; color: var(--ok); }
.inchars { display: flex; gap: 10px; margin: 8px 0 4px; }
.inchars span, .seq span { display: flex; flex-direction: column; align-items: center; }
.inchars small, .seq small { font-size: 11px; color: var(--muted); }
.seq { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0 6px; }
.rule .p { font-size: 15px; }

/* tap-to-flip */
.card.flip { cursor: pointer; }
.hint { font-size: 13px; color: var(--muted); margin-top: 22px; }
/* example sentences */
.sents { width: 100%; margin-top: 18px; border-top: 1px solid var(--line); text-align: left; }
.sent { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sent .hz { font-size: 20px; line-height: 1.35; }
.sent .hz b { color: var(--seal); font-weight: 700; }
.spy { font-size: 14px; color: var(--t4); margin-top: 2px; }
.svi { font-size: 14px; color: var(--muted); margin-top: 1px; }
.sp.sm { width: 32px; height: 32px; margin-top: 2px; font-size: 12px; }
/* grammar */
.gli { grid-template-columns: 8px 30px 1fr; }
.gn { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gli .p { font-size: 15px; }
.gt { font-size: 22px; margin: 0 0 12px; line-height: 1.3; }
.pat { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--seal); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; font-weight: 500; }
.gexp { font-size: 15px; line-height: 1.55; margin: 14px 0 0; }
.gw { white-space: nowrap; }
.gpy { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 4px; }
.qz { font-size: 26px; line-height: 1.4; }
.blank { color: var(--seal); }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.tiles.ans { min-height: 52px; border-bottom: 1px dashed var(--line); padding-bottom: 10px; width: 100%; align-items: center; }
.tile { font-family: var(--hz); font-size: 22px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.tile.on { background: var(--paper); }
.sents + .chars { border-top: 0; margin-top: 0; }

/* swipe */
#card { touch-action: pan-y; user-select: none; -webkit-user-select: none; will-change: transform; }
.stamp { position: absolute; top: 18px; font-weight: 700; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; padding: 4px 10px; border-radius: 8px; border: 2px solid; opacity: 0; transition: opacity .12s; pointer-events: none; }
.stamp.l { right: 18px; color: var(--bad); }
.stamp.r { left: 18px; color: var(--ok); }
#card.to-l .stamp.l, #card.to-r .stamp.r { opacity: 1; }
#card.to-l { border-color: var(--bad); }
#card.to-r { border-color: var(--ok); }
.swipehint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 10px; }
#card.to-l .tag, #card.to-r .tag { opacity: 0; }
html, body { overflow-x: hidden; }
.glyph { display: flex; justify-content: center; }
.card .q-prompt { margin-top: 10px; }
.ch.wch { grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.ch.wch .c { font-size: 24px; white-space: nowrap; text-align: left; min-width: 52px; }

/* ---------- island home ---------- */
body.on-isle { overflow: hidden; }
body.on-isle #app { max-width: none; padding: 0; }
.isle { position: fixed; inset: 0; background: #e9e6dc; overflow: hidden; }
.island-canvas { position: absolute; inset: 0; display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; }
.isle-ui { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: max(16px, env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom)); }
.isle-ui > * { pointer-events: auto; }
.isle-top { position: relative; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.isle-head { min-width: 0; }
.isle-title { font-family: var(--hz); font-size: 26px; font-weight: 700; color: #1c1a17; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.isle-sub { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; letter-spacing: .04em; color: #4a4438; margin-top: 2px; }
.isle-sub span, .isle-sub b { white-space: nowrap; }
.isle-sub b { color: #9a3b26; font-weight: 600; }
.isle-btn { white-space: nowrap; flex-shrink: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; padding: 7px 11px; border-radius: 8px; background: rgba(255,253,249,.82); border: 1px solid rgba(0,0,0,.08); }
.isle-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.isle-go { min-height: 50px; padding: 0 28px; border-radius: 14px; background: #1c1a17; color: #f6f1e8; font-weight: 600; font-size: 16px; box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.isle-hint { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 10px; letter-spacing: .08em; color: rgba(40,36,30,.65); text-align: center; }
body.isle-night .isle-title, body.isle-night .isle-sub, body.isle-night .isle-hint { color: #e9e4d6; text-shadow: none; }
.sheet-wrap { position: absolute; inset: 0; background: rgba(20,18,15,.28); display: flex; align-items: flex-end; justify-content: center; z-index: 5; }
.sheet-wrap[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; max-height: 82dvh; background: var(--paper); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px 10px; border-bottom: 1px solid var(--line); }
.sheet-head b { font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 14px 20px calc(20px + env(safe-area-inset-bottom)); }
.fl-word { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 14px; }
.fl-word .hz { font-size: 44px; }
.fl-steps { display: flex; flex-direction: column; gap: 6px; }
.fl-steps div { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.fl-steps i { font-style: normal; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; }
.fl-steps .ok { color: var(--ink); }
.fl-steps .ok i { background: var(--ok); border-color: var(--ok); color: #fff; }
.fl-wilt { font-size: 14px; margin: 14px 0 0; }
.fl-wilt.w0 { color: var(--ok); } .fl-wilt.w1 { color: var(--t2); } .fl-wilt.w2, .fl-wilt.w3 { color: var(--bad); }

/* writing: stroke-order markers + learning steps */
.pad .mk { position: absolute; pointer-events: none; overflow: visible; }
.steps-dots { display: flex; gap: 6px; justify-content: center; margin: 0 0 10px; flex-wrap: wrap; }
.steps-dots span { font-size: 12px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); background: var(--card); }
.steps-dots span.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.steps-dots span.done { color: var(--ok); border-color: var(--ok); }

.isle-btns { display: flex; gap: 6px; flex-shrink: 0; }
.sky-pop { position: absolute; top: calc(100% + 10px); right: 0; left: 0; max-width: 420px; margin-left: auto; background: rgba(255,253,249,.94); border: 1px solid rgba(0,0,0,.08); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; z-index: 3; }
.sky-pop[hidden] { display: none; }
.sky-row { display: flex; align-items: flex-start; gap: 6px; }
.sky-row > div { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.sky-row > span { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; color: var(--muted); width: 34px; flex-shrink: 0; line-height: 30px; }
.sky-row .chip { padding: 5px 10px; font-size: 12px; }

.menu .menu-hot .ic { color: var(--ok); }
.menu .menu-hot b { color: var(--ok); }

.opt.hzpy { flex-direction: column; justify-content: center; gap: 0; }
.opt.hzpy .hz { font-size: 28px; line-height: 1.2; }
.opt-py { font-size: 14px; color: var(--muted); }
