:root {
  --bg: #f4f1ea;
  --bg2: #ebe6db;
  --card: #fffdf8;
  --ink: #1d2321;
  --ink2: #56605b;
  --ink3: #8b938e;
  --line: #d9d3c6;
  --gold: #a87a26;
  --gold-soft: #f1e4c6;
  --leaf: #4f7f5c;
  --der: #2f68b0;
  --die: #c0443b;
  --das: #2f8a57;
  --der-soft: #dfe9f6;
  --die-soft: #f7e1de;
  --das-soft: #dcefe3;
  --again: #c0443b;
  --hard: #b8792a;
  --good: #2f8a57;
  --easy: #2f68b0;
  --shadow: 0 1px 2px rgba(29, 35, 33, .06), 0 8px 28px rgba(29, 35, 33, .08);
  --radius: 22px;
  --dock-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --zh: "PingFang TC", "Noto Sans TC", "Heiti TC", system-ui, sans-serif;
  --de: "Inter Tight", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --bg2: #1c211f; --card: #1f2522; --ink: #ecebe5; --ink2: #b3b8b2; --ink3: #7d8580;
    --line: #333b37; --gold: #d8ad5c; --gold-soft: #3a3120; --leaf: #7fb08c;
    --der: #6fa2e6; --die: #ec7a70; --das: #62c08a;
    --der-soft: #1e2b3d; --die-soft: #3b2220; --das-soft: #1b3226;
    --again: #ec7a70; --hard: #e0a656; --good: #62c08a; --easy: #6fa2e6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --bg2: #1c211f; --card: #1f2522; --ink: #ecebe5; --ink2: #b3b8b2; --ink3: #7d8580;
  --line: #333b37; --gold: #d8ad5c; --gold-soft: #3a3120; --leaf: #7fb08c;
  --der: #6fa2e6; --die: #ec7a70; --das: #62c08a;
  --der-soft: #1e2b3d; --die-soft: #3b2220; --das-soft: #1b3226;
  --again: #ec7a70; --hard: #e0a656; --good: #62c08a; --easy: #6fa2e6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--zh);
  font-size: 16px; line-height: 1.55; min-height: 100dvh;
  overflow-x: clip; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.de { font-family: var(--de); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#view {
  max-width: 560px; margin: 0 auto;
  padding: calc(18px + var(--safe-t)) 16px calc(var(--dock-h) + 28px + var(--safe-b));
}
body.focus #view { padding-bottom: calc(20px + var(--safe-b)); }
body.focus #dock { transform: translate(-50%, 160%); }

/* dock */
#dock {
  position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 2px; padding: 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  transition: transform .35s cubic-bezier(.2, .8, .2, 1); z-index: 20;
}
#dock a {
  display: grid; place-items: center; gap: 1px; width: 62px; height: 52px; border-radius: 999px;
  color: var(--ink3); text-decoration: none; font-size: 11px; letter-spacing: .04em;
  transition: background .2s, color .2s;
}
#dock a.on { color: var(--ink); background: var(--bg2); }
#dock a.on svg { color: var(--gold); }

/* type */
.eyebrow { font-family: var(--de); font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink3); }
h1.brand { font-family: var(--de); font-weight: 200; font-size: 40px; letter-spacing: .02em; margin: 2px 0 0; line-height: 1.1; }
h1.brand span { font-family: var(--zh); font-weight: 300; font-size: 18px; color: var(--ink2); margin-left: 10px; letter-spacing: .3em; }
h2 { font-size: 20px; font-weight: 600; margin: 28px 0 12px; letter-spacing: .02em; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }

/* home */
.hero { position: relative; margin: 6px -16px 0; }
.tree { display: block; width: 100%; aspect-ratio: 1 / .86; touch-action: pan-y; }
.tree-caption { text-align: center; font-size: 13px; color: var(--ink2); margin-top: 4px; }
.cta {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; margin-top: 18px; padding: 18px 20px; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  transition: transform .15s;
}
.cta:active { transform: scale(.98); }
.cta b { font-size: 18px; font-weight: 600; }
.cta .cnt { font-family: var(--de); font-size: 13px; opacity: .75; }
.cta .go { width: 42px; height: 42px; border-radius: 50%; background: var(--gold); color: #fff; display: grid; place-items: center; }
.cta.done { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.stat .n { font-family: var(--de); font-size: 26px; font-weight: 300; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--ink2); }
.countdown { margin-top: 10px; font-size: 13px; color: var(--ink2); display: flex; align-items: center; gap: 8px; }
.countdown b { color: var(--gold); font-family: var(--de); font-weight: 500; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px; display: grid; gap: 8px; transition: transform .15s, border-color .2s;
}
.tile:active { transform: scale(.97); }
.tile .ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); }
.tile b { font-size: 15px; }
.tile span { font-size: 12px; color: var(--ink2); line-height: 1.4; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 13px; height: 13px; border-radius: 3px; background: var(--bg2); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--leaf) 30%, var(--bg2)); }
.heat i.l2 { background: color-mix(in srgb, var(--leaf) 55%, var(--bg2)); }
.heat i.l3 { background: color-mix(in srgb, var(--leaf) 80%, var(--bg2)); }
.heat i.l4 { background: var(--leaf); }
.heat i.today { outline: 1.5px solid var(--gold); outline-offset: 1px; }

/* review */
.rv-top { display: flex; align-items: center; gap: 12px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink2); background: var(--card); border: 1px solid var(--line); flex: none; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { color: var(--gold); border-color: var(--gold); }
.bar { flex: 1; height: 6px; border-radius: 6px; background: var(--bg2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--gold); border-radius: 6px; transition: width .4s; }
.counts { font-family: var(--de); font-size: 13px; display: flex; gap: 10px; }
.counts .n { color: var(--easy); } .counts .l { color: var(--again); } .counts .r { color: var(--good); }
.counts .cur { text-decoration: underline; text-underline-offset: 4px; }

.stage { perspective: 1400px; margin-top: 18px; touch-action: pan-y; }
.card {
  position: relative; min-height: min(62dvh, 520px); border-radius: 28px;
  transform-style: preserve-3d; transition: transform .55s cubic-bezier(.3, 1.3, .5, 1);
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.card.flipped { transform: rotateY(180deg); }
.card.dragging { transition: none; }
.card.enter { animation: enter .45s cubic-bezier(.2, 1, .3, 1); }
@keyframes enter { from { transform: translateY(26px) scale(.96); opacity: 0; } }
.face {
  position: absolute; inset: 0; border-radius: 28px; background: var(--card); box-shadow: var(--shadow);
  border: 1px solid var(--line); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 28px 22px; overflow: hidden;
}
.face.back { transform: rotateY(180deg); justify-content: flex-start; padding-top: 34px; overflow-y: auto; }
.face::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: var(--g, transparent); }
.card[data-g="der"] { --g: var(--der); --gs: var(--der-soft); }
.card[data-g="die"] { --g: var(--die); --gs: var(--die-soft); }
.card[data-g="das"] { --g: var(--das); --gs: var(--das-soft); }
.tag { font-size: 12px; color: var(--ink3); letter-spacing: .12em; position: absolute; top: 18px; left: 22px; }
.tag.r { left: auto; right: 22px; }
.word { font-family: var(--de); font-weight: 300; font-size: clamp(34px, 10vw, 48px); line-height: 1.15; letter-spacing: -.01em; word-break: break-word; }
.word .art { color: var(--g); font-weight: 400; margin-right: .25em; }
.word.sm { font-size: clamp(24px, 6.6vw, 30px); }
.zh-big { font-size: 26px; font-weight: 500; margin-top: 10px; }
.zh-q { font-size: clamp(24px, 7vw, 30px); font-weight: 500; line-height: 1.4; }
.hint { color: var(--ink3); font-size: 13px; margin-top: 18px; }
.meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.chip { font-size: 13px; padding: 4px 11px; border-radius: 999px; background: var(--bg2); color: var(--ink2); }
.chip.g { background: var(--gs); color: var(--g); }
.chip .de { color: var(--ink); }
.ex { margin-top: 18px; padding: 14px 16px; border-radius: 16px; background: var(--bg2); width: 100%; text-align: left; display: flex; gap: 12px; align-items: flex-start; }
.ex .t { flex: 1; }
.ex .d { font-family: var(--de); font-size: 17px; }
.ex .z { font-size: 14px; color: var(--ink2); margin-top: 2px; }
.ch { margin-top: 14px; width: 100%; text-align: left; padding: 12px 16px; border-radius: 16px; border: 1px dashed var(--gold); }
.ch { display: flex; align-items: center; gap: 12px; }
.ch .t { flex: 1; }
.ch .lab { font-size: 11px; letter-spacing: .14em; color: var(--gold); }
.ch .d { font-family: var(--de); font-size: 18px; }
.note { margin-top: 12px; font-size: 14px; color: var(--ink2); text-align: left; width: 100%; display: flex; gap: 8px; }
.note svg { color: var(--gold); width: 18px; height: 18px; margin-top: 3px; }
.speak { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--bg2); color: var(--ink2); margin-top: 16px; transition: transform .15s; }
.speak:active, .speak.playing { transform: scale(.92); color: var(--gold); }
.speak.sm { width: 34px; height: 34px; margin: 0; background: var(--card); }
.speak.sm svg { width: 18px; height: 18px; }
.row-btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.row-btns .speak { margin-top: 0; }

.grade { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grade button {
  padding: 10px 4px 9px; border-radius: 16px; background: var(--card); border: 1px solid var(--line);
  display: grid; gap: 1px; transition: transform .12s, background .2s;
}
.grade button:active { transform: scale(.95); }
.grade b { font-size: 15px; font-weight: 600; }
.grade small { font-family: var(--de); font-size: 12px; color: var(--ink3); }
.grade .g1 b { color: var(--again); } .grade .g2 b { color: var(--hard); } .grade .g3 b { color: var(--good); } .grade .g4 b { color: var(--easy); }
.flip-btn { width: 100%; margin-top: 16px; padding: 16px; border-radius: 18px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 16px; }
.flip-btn:active { transform: scale(.98); }
.swipe-hint { text-align: center; font-size: 12px; color: var(--ink3); margin-top: 10px; }
.stamp {
  position: absolute; top: 40%; font-family: var(--de); font-size: 22px; font-weight: 600; letter-spacing: .1em;
  padding: 6px 14px; border-radius: 12px; border: 2px solid currentColor; opacity: 0; pointer-events: none; z-index: 3;
  transform: rotateY(180deg);
}
.stamp.l { right: 26px; color: var(--again); } .stamp.r { left: 26px; color: var(--good); }

.done-wrap { text-align: center; padding-top: 6vh; }
.done-wrap .big { font-family: var(--de); font-weight: 200; font-size: 64px; line-height: 1; }
.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 8px; padding: 13px 22px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:active { transform: scale(.97); }
.btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 24px; }

/* game */
.game { text-align: center; }
.ring { width: 84px; height: 84px; margin: 6px auto 0; position: relative; }
.ring svg { width: 84px; height: 84px; transform: rotate(-90deg); }
.ring .t { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--de); font-size: 26px; font-weight: 300; }
.g-word { font-family: var(--de); font-weight: 300; font-size: clamp(38px, 12vw, 56px); margin: 6vh 0 4px; min-height: 1.3em; }
.g-word.ok { animation: pop .35s; } .g-word.bad { animation: shake .4s; }
@keyframes pop { 40% { transform: scale(1.12); } }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.g-zh { color: var(--ink2); min-height: 1.6em; }
.g-fb { height: 28px; font-family: var(--de); font-size: 18px; font-weight: 500; }
.arts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4vh; }
.arts button { padding: 26px 0; border-radius: 22px; font-family: var(--de); font-size: 24px; font-weight: 500; color: #fff; box-shadow: var(--shadow); transition: transform .1s; }
.arts button:active { transform: scale(.94); }
.arts .der { background: var(--der); } .arts .die { background: var(--die); } .arts .das { background: var(--das); }
.score { display: flex; justify-content: center; gap: 22px; margin-top: 10px; font-family: var(--de); }
.score b { font-size: 22px; font-weight: 400; }
.score span { display: block; font-family: var(--zh); font-size: 12px; color: var(--ink3); }
.combo { color: var(--gold); }
.miss { text-align: left; margin-top: 18px; }
.miss li { font-family: var(--de); padding: 4px 0; }

/* lists */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 8px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { white-space: nowrap; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.list { display: grid; gap: 10px; margin-top: 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 14px 14px 16px; display: flex; gap: 12px; align-items: center; }
.item .t { flex: 1; min-width: 0; }
.item .d { font-family: var(--de); font-size: 17px; }
.item .z { font-size: 14px; color: var(--ink2); }
.item .c { font-size: 13px; color: var(--gold); font-family: var(--de); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.speak.xs { width: 26px; height: 26px; margin: 0 0 0 6px; background: var(--bg2); color: var(--gold); display: inline-grid; vertical-align: middle; }
.speak.xs svg { width: 15px; height: 15px; }
.item .n { font-size: 12px; color: var(--ink3); margin-top: 2px; }
.item .acts { display: flex; gap: 6px; }
.lesson-row { text-align: left; width: 100%; }
.lesson-row .num { font-family: var(--de); font-size: 13px; color: var(--ink3); width: 26px; }
.lesson-row .ok { color: var(--good); }

/* lesson */
.lesson h1 { font-size: 24px; font-weight: 600; margin: 10px 0 6px; line-height: 1.35; }
.lesson .lead { color: var(--ink2); margin: 0 0 18px; }
.lesson p { margin: 12px 0; }
.lesson table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 15px; background: var(--card); border-radius: 14px; overflow: hidden; }
.lesson th, .lesson td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.lesson th { font-size: 12px; color: var(--ink3); font-weight: 500; letter-spacing: .06em; background: var(--bg2); }
.lesson tr:last-child td { border-bottom: 0; }
.lesson .tbl { overflow-x: auto; }
.lesson .ex { margin-top: 10px; background: var(--card); border: 1px solid var(--line); }
.lesson .ex mark { background: var(--gold-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.tipbox { margin: 14px 0; padding: 12px 14px; border-radius: 14px; background: var(--gold-soft); font-size: 15px; display: flex; gap: 10px; }
.tipbox svg { color: var(--gold); margin-top: 2px; }
.quiz { margin-top: 26px; }
.q { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-top: 12px; }
.q .qt { font-weight: 600; }
.q .opts { display: grid; gap: 8px; margin-top: 12px; }
.q .opts button { text-align: left; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); transition: background .2s, border-color .2s; }
.q .opts button.right { border-color: var(--good); background: var(--das-soft); }
.q .opts button.wrong { border-color: var(--again); background: var(--die-soft); }
.q .why { margin-top: 10px; font-size: 14px; color: var(--ink2); }

/* sheet (speaking practice) */
.sheet[hidden], .toast[hidden] { display: none !important; }
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(10, 14, 12, .38); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet .panel {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 26px 26px 0 0; padding: 22px 18px calc(24px + var(--safe-b));
  animation: up .35s cubic-bezier(.2, 1, .3, 1); max-height: 88dvh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(40%); } }
.sheet .grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: -8px auto 14px; }
.target { font-family: var(--de); font-size: 22px; text-align: center; line-height: 1.4; }
.target .w { padding: 0 1px; border-radius: 4px; transition: background .3s, color .3s; }
.target .w.hit { color: var(--good); }
.target .w.miss { color: var(--again); text-decoration: underline wavy; text-underline-offset: 5px; }
.mic {
  width: 84px; height: 84px; border-radius: 50%; margin: 22px auto 8px; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); position: relative; transition: transform .15s;
}
.mic svg { width: 32px; height: 32px; }
.mic.rec { background: var(--again); color: #fff; }
.mic.rec::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--again); animation: pulse 1.2s infinite; }
@keyframes pulse { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.heard { text-align: center; font-family: var(--de); color: var(--ink2); min-height: 1.6em; }
.pct { text-align: center; font-family: var(--de); font-size: 40px; font-weight: 200; }

/* settings */
.set { background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.set label, .set .r { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.set > :last-child { border-bottom: 0; }
.set .sub { font-size: 12px; color: var(--ink3); }
.set select, .set input[type="date"] { background: var(--bg2); border: 0; border-radius: 10px; padding: 6px 10px; max-width: 52%; }
.set input[type="range"] { width: 44%; accent-color: var(--gold); }
.sw { position: relative; width: 50px; height: 30px; flex: none; }
.sw input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; }
.sw i { position: absolute; inset: 0; border-radius: 30px; background: var(--line); transition: background .2s; pointer-events: none; }
.sw i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s; }
.sw input:checked + i { background: var(--leaf); }
.sw input:checked + i::after { transform: translateX(20px); }
.danger { color: var(--again); }

.toast { position: fixed; left: 50%; bottom: calc(var(--dock-h) + 30px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50; box-shadow: var(--shadow); animation: fade .2s; max-width: calc(100vw - 32px); }

.burst { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 700px) {
  #view { padding-top: 40px; }
}
